From 29fb2631cbeace0db5f1c2ae63fd576808a0579b Mon Sep 17 00:00:00 2001 From: M M Arif Date: Thu, 14 Nov 2019 21:58:38 +0500 Subject: [PATCH] refactored credit activtiy --- .../gitnex/activities/CreditsActivity.java | 30 ++++++++-- .../mian/gitnex/adapters/CreditsAdapter.java | 59 +++++++++++++++++++ .../mian/gitnex/adapters/SponsorsAdapter.java | 4 +- app/src/main/res/layout/activity_credits.xml | 51 +++++----------- app/src/main/res/layout/activity_sponsors.xml | 1 - app/src/main/res/layout/credits.xml | 21 +++++++ app/src/main/res/values/credits.xml | 8 +++ .../{credits_sponsors.xml => sponsors.xml} | 5 -- app/src/main/res/values/strings.xml | 4 -- 9 files changed, 129 insertions(+), 54 deletions(-) create mode 100644 app/src/main/java/org/mian/gitnex/adapters/CreditsAdapter.java create mode 100644 app/src/main/res/layout/credits.xml create mode 100644 app/src/main/res/values/credits.xml rename app/src/main/res/values/{credits_sponsors.xml => sponsors.xml} (63%) diff --git a/app/src/main/java/org/mian/gitnex/activities/CreditsActivity.java b/app/src/main/java/org/mian/gitnex/activities/CreditsActivity.java index 37e3ebee..9c3bddb7 100644 --- a/app/src/main/java/org/mian/gitnex/activities/CreditsActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/CreditsActivity.java @@ -1,12 +1,18 @@ package org.mian.gitnex.activities; import androidx.appcompat.app.AppCompatActivity; +import androidx.recyclerview.widget.DividerItemDecoration; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; +import android.content.res.Resources; import android.os.Bundle; -import android.text.method.LinkMovementMethod; import android.view.View; import android.widget.ImageView; -import android.widget.TextView; import org.mian.gitnex.R; +import org.mian.gitnex.adapters.CreditsAdapter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; /** * Author M M Arif @@ -22,14 +28,28 @@ public class CreditsActivity extends AppCompatActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_credits); - TextView creditKasun = findViewById(R.id.creditKasun); ImageView closeActivity = findViewById(R.id.close); - creditKasun.setMovementMethod(LinkMovementMethod.getInstance()); - initCloseListener(); closeActivity.setOnClickListener(onClickListener); + Resources res = getResources(); + CharSequence[] creditsInfo = res.getTextArray(R.array.creditsInfo); + + List creditsList = new ArrayList<>(Arrays.asList(creditsInfo)); + + RecyclerView mRecyclerView = findViewById(R.id.recyclerView); + + mRecyclerView.setHasFixedSize(true); + mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + + DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(), + DividerItemDecoration.VERTICAL); + mRecyclerView.addItemDecoration(dividerItemDecoration); + + CreditsAdapter adapter = new CreditsAdapter(creditsList); + mRecyclerView.setAdapter(adapter); + } private void initCloseListener() { diff --git a/app/src/main/java/org/mian/gitnex/adapters/CreditsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/CreditsAdapter.java new file mode 100644 index 00000000..2ec35f66 --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/adapters/CreditsAdapter.java @@ -0,0 +1,59 @@ +package org.mian.gitnex.adapters; + +import android.text.SpannableStringBuilder; +import android.text.method.LinkMovementMethod; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; +import org.mian.gitnex.R; +import java.util.List; + +/** + * Author M M Arif + */ + +public class CreditsAdapter extends RecyclerView.Adapter { + + private List creditsList; + + static class CreditsViewHolder extends RecyclerView.ViewHolder { + + private TextView creditText; + + private CreditsViewHolder(View itemView) { + super(itemView); + + creditText = itemView.findViewById(R.id.creditText); + + } + } + + public CreditsAdapter(List creditsListMain) { + this.creditsList = creditsListMain; + } + + @NonNull + @Override + public CreditsAdapter.CreditsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.credits, parent, false); + return new CreditsAdapter.CreditsViewHolder(v); + } + + @Override + public void onBindViewHolder(@NonNull CreditsAdapter.CreditsViewHolder holder, int position) { + + SpannableStringBuilder strBuilder = new SpannableStringBuilder(creditsList.get(position)); + holder.creditText.setText((strBuilder)); + holder.creditText.setMovementMethod(LinkMovementMethod.getInstance()); + + } + + @Override + public int getItemCount() { + return creditsList.size(); + } + +} diff --git a/app/src/main/java/org/mian/gitnex/adapters/SponsorsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/SponsorsAdapter.java index fb24b5e0..a1120cbe 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/SponsorsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/SponsorsAdapter.java @@ -31,8 +31,8 @@ public class SponsorsAdapter extends RecyclerView.Adapter myListMain) { - this.sponsorsList = myListMain; + public SponsorsAdapter(List sponsorsListMain) { + this.sponsorsList = sponsorsListMain; } @NonNull diff --git a/app/src/main/res/layout/activity_credits.xml b/app/src/main/res/layout/activity_credits.xml index aa65ad27..09999d87 100644 --- a/app/src/main/res/layout/activity_credits.xml +++ b/app/src/main/res/layout/activity_credits.xml @@ -1,4 +1,6 @@ - + - + android:layout_height="wrap_content" + android:orientation="vertical"> - + android:layout_height="match_parent" + android:background="@color/colorPrimary" + android:padding="4dp" + android:scrollbars="vertical" /> - - - - - - - - - + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_sponsors.xml b/app/src/main/res/layout/activity_sponsors.xml index 52d2b949..30f1cbfc 100644 --- a/app/src/main/res/layout/activity_sponsors.xml +++ b/app/src/main/res/layout/activity_sponsors.xml @@ -42,7 +42,6 @@ - + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/credits.xml b/app/src/main/res/values/credits.xml new file mode 100644 index 00000000..91bb10a8 --- /dev/null +++ b/app/src/main/res/values/credits.xml @@ -0,0 +1,8 @@ + + + + + Logo by Kasun @kasun + + + \ No newline at end of file diff --git a/app/src/main/res/values/credits_sponsors.xml b/app/src/main/res/values/sponsors.xml similarity index 63% rename from app/src/main/res/values/credits_sponsors.xml rename to app/src/main/res/values/sponsors.xml index 3588fce1..dbd9feab 100644 --- a/app/src/main/res/values/credits_sponsors.xml +++ b/app/src/main/res/values/sponsors.xml @@ -1,11 +1,6 @@ - - Logo by Kasun @Mastodon - Credit 2 - - Fabian Stamm Thomas Schneider @Fedilab diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c16fbc05..275aa2de 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -285,10 +285,6 @@ Design - - Logo by Kasun @Mastodon - - Authorization Error It seems that the Access Token is revoked OR your are not allowed to see these contents. In case of revoked Token, please logout and login again Cancel