From d7f85cb471038498332195c9a1bdea794ec32068 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Tue, 29 Sep 2020 00:09:33 +0800 Subject: Add translation contributors in Settigs->About->Translation. --- .../AcknowledgementRecyclerViewAdapter.java | 70 ++++++++++++++++++ .../TranslationFragmentRecyclerViewAdapter.java | 82 ++++++++++++++++++++++ .../infinityforreddit/AppComponent.java | 3 + .../Settings/Acknowledgement.java | 2 +- .../Settings/AcknowledgementFragment.java | 1 + .../AcknowledgementRecyclerViewAdapter.java | 69 ------------------ .../infinityforreddit/Settings/Translation.java | 42 +++++++++++ .../Settings/TranslationFragment.java | 58 +++++++++++++++ 8 files changed, 257 insertions(+), 70 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/AcknowledgementRecyclerViewAdapter.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/TranslationFragmentRecyclerViewAdapter.java delete mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AcknowledgementRecyclerViewAdapter.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Settings/Translation.java create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Settings/TranslationFragment.java (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/AcknowledgementRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/AcknowledgementRecyclerViewAdapter.java new file mode 100644 index 00000000..3958054a --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/AcknowledgementRecyclerViewAdapter.java @@ -0,0 +1,70 @@ +package ml.docilealligator.infinityforreddit.Adapter; + +import android.content.Context; +import android.content.Intent; +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 java.util.ArrayList; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.Settings.Acknowledgement; + +public class AcknowledgementRecyclerViewAdapter extends RecyclerView.Adapter { + private ArrayList acknowledgements; + private Context context; + + public AcknowledgementRecyclerViewAdapter(Context context, ArrayList acknowledgements) { + this.context = context; + this.acknowledgements = acknowledgements; + } + + @NonNull + @Override + public AcknowledgementViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new AcknowledgementViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_acknowledgement, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull AcknowledgementViewHolder holder, int position) { + Acknowledgement acknowledgement = acknowledgements.get(holder.getAdapterPosition()); + if (acknowledgement != null) { + holder.nameTextView.setText(acknowledgement.getName()); + holder.introductionTextView.setText(acknowledgement.getIntroduction()); + holder.itemView.setOnClickListener(view -> { + if (context != null) { + Intent intent = new Intent(context, LinkResolverActivity.class); + intent.setData(acknowledgement.getLink()); + context.startActivity(intent); + } + }); + } + } + + @Override + public int getItemCount() { + return acknowledgements == null ? 0 : acknowledgements.size(); + } + + class AcknowledgementViewHolder extends RecyclerView.ViewHolder { + View itemView; + @BindView(R.id.name_text_view_item_acknowledgement) + TextView nameTextView; + @BindView(R.id.introduction_text_view_item_acknowledgement) + TextView introductionTextView; + + AcknowledgementViewHolder(@NonNull View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + this.itemView = itemView; + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/TranslationFragmentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/TranslationFragmentRecyclerViewAdapter.java new file mode 100644 index 00000000..a31381c5 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/TranslationFragmentRecyclerViewAdapter.java @@ -0,0 +1,82 @@ +package ml.docilealligator.infinityforreddit.Adapter; + +import android.app.Activity; +import android.content.Intent; +import android.net.Uri; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import androidx.annotation.NonNull; +import androidx.recyclerview.widget.RecyclerView; + +import java.util.ArrayList; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.R; +import ml.docilealligator.infinityforreddit.Settings.Translation; + +public class TranslationFragmentRecyclerViewAdapter extends RecyclerView.Adapter { + private Activity activity; + private int primaryTextColor; + private int secondaryTextColor; + private ArrayList translationContributors; + + public TranslationFragmentRecyclerViewAdapter(Activity activity, CustomThemeWrapper customThemeWrapper) { + this.activity = activity; + primaryTextColor = customThemeWrapper.getPrimaryTextColor(); + secondaryTextColor = customThemeWrapper.getSecondaryTextColor(); + translationContributors = Translation.getTranslationContributors(); + } + + @NonNull + @Override + public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { + return new TranslationContributorViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_translation_contributor, parent, false)); + } + + @Override + public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) { + if (holder instanceof TranslationContributorViewHolder) { + Translation translation = translationContributors.get(position); + ((TranslationContributorViewHolder) holder).countryFlagImageView.setImageResource(translation.flagDrawableId); + ((TranslationContributorViewHolder) holder).languageNameTextView.setText(translation.language); + ((TranslationContributorViewHolder) holder).contributorNamesTextView.setText(translation.contributors); + } + } + + @Override + public int getItemCount() { + return translationContributors.size(); + } + + class TranslationContributorViewHolder extends RecyclerView.ViewHolder { + + @BindView(R.id.country_flag_image_view_item_translation_contributor) + ImageView countryFlagImageView; + @BindView(R.id.language_name_text_view_item_translation_contributor) + TextView languageNameTextView; + @BindView(R.id.contributor_names_text_view_item_translation_contributor) + TextView contributorNamesTextView; + + public TranslationContributorViewHolder(@NonNull View itemView) { + super(itemView); + + ButterKnife.bind(this, itemView); + + languageNameTextView.setTextColor(primaryTextColor); + contributorNamesTextView.setTextColor(secondaryTextColor); + + itemView.setOnClickListener(view -> { + Intent intent = new Intent(activity, LinkResolverActivity.class); + intent.setData(Uri.parse("https://poeditor.com/join/project?hash=b2IRyfaJv6")); + activity.startActivity(intent); + }); + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java index e7c8e456..e537b248 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java @@ -71,6 +71,7 @@ import ml.docilealligator.infinityforreddit.Settings.NotificationPreferenceFragm import ml.docilealligator.infinityforreddit.Settings.NsfwAndBlurringFragment; import ml.docilealligator.infinityforreddit.Settings.SecurityPreferenceFragment; import ml.docilealligator.infinityforreddit.Settings.ThemePreferenceFragment; +import ml.docilealligator.infinityforreddit.Settings.TranslationFragment; import ml.docilealligator.infinityforreddit.Settings.VideoPreferenceFragment; @Singleton @@ -215,4 +216,6 @@ public interface AppComponent { void inject(CustomizeBottomAppBarFragment customizeBottomAppBarFragment); void inject(GiveAwardActivity giveAwardActivity); + + void inject(TranslationFragment translationFragment); } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/Acknowledgement.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/Acknowledgement.java index 9291b53c..f3466268 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/Acknowledgement.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/Acknowledgement.java @@ -2,7 +2,7 @@ package ml.docilealligator.infinityforreddit.Settings; import android.net.Uri; -class Acknowledgement { +public class Acknowledgement { private String name; private String introduction; private Uri link; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AcknowledgementFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AcknowledgementFragment.java index c765682e..feb13e66 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AcknowledgementFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AcknowledgementFragment.java @@ -18,6 +18,7 @@ import java.util.ArrayList; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Adapter.AcknowledgementRecyclerViewAdapter; import ml.docilealligator.infinityforreddit.R; /** diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AcknowledgementRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AcknowledgementRecyclerViewAdapter.java deleted file mode 100644 index 6b081ad1..00000000 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/AcknowledgementRecyclerViewAdapter.java +++ /dev/null @@ -1,69 +0,0 @@ -package ml.docilealligator.infinityforreddit.Settings; - -import android.content.Context; -import android.content.Intent; -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 java.util.ArrayList; - -import butterknife.BindView; -import butterknife.ButterKnife; -import ml.docilealligator.infinityforreddit.Activity.LinkResolverActivity; -import ml.docilealligator.infinityforreddit.R; - -class AcknowledgementRecyclerViewAdapter extends RecyclerView.Adapter { - private ArrayList acknowledgements; - private Context context; - - AcknowledgementRecyclerViewAdapter(Context context, ArrayList acknowledgements) { - this.context = context; - this.acknowledgements = acknowledgements; - } - - @NonNull - @Override - public AcknowledgementViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - return new AcknowledgementViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_acknowledgement, parent, false)); - } - - @Override - public void onBindViewHolder(@NonNull AcknowledgementViewHolder holder, int position) { - Acknowledgement acknowledgement = acknowledgements.get(holder.getAdapterPosition()); - if (acknowledgement != null) { - holder.nameTextView.setText(acknowledgement.getName()); - holder.introductionTextView.setText(acknowledgement.getIntroduction()); - holder.itemView.setOnClickListener(view -> { - if (context != null) { - Intent intent = new Intent(context, LinkResolverActivity.class); - intent.setData(acknowledgement.getLink()); - context.startActivity(intent); - } - }); - } - } - - @Override - public int getItemCount() { - return acknowledgements == null ? 0 : acknowledgements.size(); - } - - class AcknowledgementViewHolder extends RecyclerView.ViewHolder { - View itemView; - @BindView(R.id.name_text_view_item_acknowledgement) - TextView nameTextView; - @BindView(R.id.introduction_text_view_item_acknowledgement) - TextView introductionTextView; - - AcknowledgementViewHolder(@NonNull View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - this.itemView = itemView; - } - } -} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/Translation.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/Translation.java new file mode 100644 index 00000000..3d809a7f --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/Translation.java @@ -0,0 +1,42 @@ +package ml.docilealligator.infinityforreddit.Settings; + +import java.util.ArrayList; + +import ml.docilealligator.infinityforreddit.R; + +public class Translation { + public String language; + public String contributors; + public int flagDrawableId; + + public Translation(String language, String contributors, int flagDrawableId) { + this.language = language; + this.contributors = contributors; + this.flagDrawableId = flagDrawableId; + } + + public static ArrayList getTranslationContributors() { + ArrayList translationContributors = new ArrayList<>(); + translationContributors.add(new Translation("简体中文", "Gloria, Justin", R.drawable.flag_china)); + translationContributors.add(new Translation("繁體中文", "", R.drawable.flag_china)); + translationContributors.add(new Translation("Hrvatski", "Josip", R.drawable.flag_croatia)); + translationContributors.add(new Translation("Française", "367, oursonbleu, Owen, pinembour", R.drawable.flag_france)); + translationContributors.add(new Translation("Deutsche", "Jorge, Netto Hikari, translatewingman, translatorwiz", R.drawable.flag_germany)); + translationContributors.add(new Translation("Ελληνικά", "Marios, Viktor", R.drawable.flag_greece)); + translationContributors.add(new Translation("हिंदी", "a, Arya, charu, Mrigendra Bhandari, raghav, Sachin, Ved", R.drawable.flag_india)); + translationContributors.add(new Translation("Magyar", "Zoltan", R.drawable.flag_hungary)); + translationContributors.add(new Translation("Italiana", "Daniele Basso, DanOlivaw, Gianni00palmieri, Gillauino, ztiaa", R.drawable.flag_italy)); + translationContributors.add(new Translation("日本語", "Issa, Mrigendra Bhandari, Ryan", R.drawable.flag_japan)); + translationContributors.add(new Translation("한국어", "noname", R.drawable.flag_south_korea)); + translationContributors.add(new Translation("norsk", "", R.drawable.flag_norway)); + translationContributors.add(new Translation("Português", "Bruno Guerreiro, Lucas", R.drawable.flag_portugal)); + translationContributors.add(new Translation("Português (BR)", "Laura Vasconcellos Pereira Felippe, Ricky, Super_Iguanna", R.drawable.flag_brazil)); + translationContributors.add(new Translation("Română", "", R.drawable.flag_romania)); + translationContributors.add(new Translation("русский язык", "aveblazer, flexagoon, Georgiy, Vova", R.drawable.flag_russia)); + translationContributors.add(new Translation("Español", "Jorge, Miguel, mvstermoe, Nana Snixx, Sofia Flores", R.drawable.flag_spain)); + translationContributors.add(new Translation("svenska", "Marcus Nordberg", R.drawable.flag_sweden)); + translationContributors.add(new Translation("Türk", "Emir481, Faoiltiarna, Mehmet Yavuz, Serif", R.drawable.flag_turkey)); + translationContributors.add(new Translation("Tiếng Việt", "Kai, Laezzy, Lmao, Ryan, viecdet69", R.drawable.flag_vietnam)); + return translationContributors; + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/TranslationFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/TranslationFragment.java new file mode 100644 index 00000000..44ad57e8 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Settings/TranslationFragment.java @@ -0,0 +1,58 @@ +package ml.docilealligator.infinityforreddit.Settings; + +import android.app.Activity; +import android.content.Context; +import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + +import androidx.annotation.NonNull; +import androidx.fragment.app.Fragment; +import androidx.recyclerview.widget.LinearLayoutManager; +import androidx.recyclerview.widget.RecyclerView; + +import javax.inject.Inject; + +import butterknife.BindView; +import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.Adapter.TranslationFragmentRecyclerViewAdapter; +import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper; +import ml.docilealligator.infinityforreddit.Infinity; +import ml.docilealligator.infinityforreddit.R; + +public class TranslationFragment extends Fragment { + + @BindView(R.id.recycler_view_translation_fragment) + RecyclerView recyclerView; + @Inject + CustomThemeWrapper customThemeWrapper; + private Activity activity; + + public TranslationFragment() { + // Required empty public constructor + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + View rootView = inflater.inflate(R.layout.fragment_translation, container, false); + + ((Infinity) activity.getApplication()).getAppComponent().inject(this); + + ButterKnife.bind(this, rootView); + + TranslationFragmentRecyclerViewAdapter adapter = new TranslationFragmentRecyclerViewAdapter(activity, customThemeWrapper); + recyclerView.setLayoutManager(new LinearLayoutManager(activity)); + recyclerView.setAdapter(adapter); + + return rootView; + } + + @Override + public void onAttach(@NonNull Context context) { + super.onAttach(context); + activity = (Activity) context; + } +} \ No newline at end of file -- cgit v1.2.3