From 881aad5f2d5967c0a3bbc21e579067b2493e654d Mon Sep 17 00:00:00 2001 From: M M Arif Date: Sun, 30 May 2021 19:28:14 +0200 Subject: [PATCH] New About App dialog, improvements and fixes (#922) Possible fix for #917 Co-authored-by: M M Arif Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/922 Reviewed-by: opyale Co-authored-by: M M Arif Co-committed-by: M M Arif --- .../activities/IssueDetailActivity.java | 8 +- .../adapters/AdminCronTasksAdapter.java | 6 +- .../mian/gitnex/adapters/CommitsAdapter.java | 15 +- ...Adapter.java => ExploreIssuesAdapter.java} | 24 +- ...=> ExplorePublicOrganizationsAdapter.java} | 10 +- .../adapters/ExploreRepositoriesAdapter.java | 25 +- .../gitnex/adapters/IssueCommentsAdapter.java | 31 +- .../mian/gitnex/adapters/IssuesAdapter.java | 8 +- .../gitnex/adapters/MyReposListAdapter.java | 8 +- .../gitnex/adapters/PullRequestsAdapter.java | 4 +- .../mian/gitnex/adapters/ReleasesAdapter.java | 4 +- .../gitnex/adapters/RepoForksAdapter.java | 8 +- .../gitnex/adapters/ReposListAdapter.java | 8 +- .../adapters/RepositoriesByOrgAdapter.java | 8 +- .../adapters/StarredReposListAdapter.java | 8 +- .../mian/gitnex/fragments/AboutFragment.java | 88 ------ .../fragments/ExploreIssuesFragment.java | 6 +- .../ExplorePublicOrganizationsFragment.java | 6 +- .../ExploreRepositoriesFragment.java | 41 +-- .../gitnex/fragments/RepoInfoFragment.java | 8 +- .../gitnex/fragments/SettingsFragment.java | 62 +++- .../helpers/ssl/MemorizingTrustManager.java | 8 +- .../gitnex/viewmodels/FilesViewModel.java | 43 +-- .../main/res/layout/custom_about_dialog.xml | 205 ++++++++++++++ app/src/main/res/layout/fragment_about.xml | 264 ------------------ .../res/values/{arrays.xml => settings.xml} | 1 - app/src/main/res/values/strings.xml | 3 +- 27 files changed, 346 insertions(+), 564 deletions(-) rename app/src/main/java/org/mian/gitnex/adapters/{SearchIssuesAdapter.java => ExploreIssuesAdapter.java} (89%) rename app/src/main/java/org/mian/gitnex/adapters/{PublicOrganizationsAdapter.java => ExplorePublicOrganizationsAdapter.java} (87%) delete mode 100644 app/src/main/java/org/mian/gitnex/fragments/AboutFragment.java create mode 100644 app/src/main/res/layout/custom_about_dialog.xml delete mode 100644 app/src/main/res/layout/fragment_about.xml rename app/src/main/res/values/{arrays.xml => settings.xml} (99%) diff --git a/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java b/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java index 2deae15a..afa16ada 100644 --- a/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java @@ -569,7 +569,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt } TinyDB tinyDb = TinyDB.getInstance(appCtx); - final String locale = getResources().getConfiguration().locale.getLanguage(); + final Locale locale = getResources().getConfiguration().locale; final String timeFormat = tinyDb.getString("dateFormat"); tinyDb.putString("issueState", singleIssue.getState()); tinyDb.putString("issueTitle", singleIssue.getTitle()); @@ -660,7 +660,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt if(timeFormat.equals("normal") || timeFormat.equals("pretty")) { - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", new Locale(locale)); + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", locale); String dueDate = formatter.format(singleIssue.getDue_date()); viewBinding.issueDueDate.setText(dueDate); viewBinding.issueDueDate @@ -668,7 +668,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt } else if(timeFormat.equals("normal1")) { - DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", new Locale(locale)); + DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", locale); String dueDate = formatter.format(singleIssue.getDue_date()); viewBinding.issueDueDate.setText(dueDate); } @@ -714,7 +714,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt viewBinding.issueDescription.setLayoutParams(paramsDesc); } - viewBinding.issueCreatedTime.setText(TimeHelper.formatTime(singleIssue.getCreated_at(), new Locale(locale), timeFormat, ctx)); + viewBinding.issueCreatedTime.setText(TimeHelper.formatTime(singleIssue.getCreated_at(), locale, timeFormat, ctx)); viewBinding.issueCreatedTime.setVisibility(View.VISIBLE); if(timeFormat.equals("pretty")) { diff --git a/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java index c8be42c4..38d78019 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java @@ -44,7 +44,7 @@ public class AdminCronTasksAdapter extends RecyclerView.Adapter= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) { - isLoading = true; loadMoreListener.onLoadMore(); } if(getItemViewType(position) == TYPE_LOAD) { - ((CommitsHolder) holder).bindData(commitsList.get(position)); } } @@ -106,18 +104,16 @@ public class CommitsAdapter extends RecyclerView.Adapter context.startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(commitsModel.getHtml_url())))); } @@ -126,36 +122,29 @@ public class CommitsAdapter extends RecyclerView.Adapter list) { - commitsList = list; notifyDataSetChanged(); } - } diff --git a/app/src/main/java/org/mian/gitnex/adapters/SearchIssuesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ExploreIssuesAdapter.java similarity index 89% rename from app/src/main/java/org/mian/gitnex/adapters/SearchIssuesAdapter.java rename to app/src/main/java/org/mian/gitnex/adapters/ExploreIssuesAdapter.java index b827dbcb..e24250c0 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/SearchIssuesAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ExploreIssuesAdapter.java @@ -33,13 +33,13 @@ import java.util.Locale; * Author M M Arif */ -public class SearchIssuesAdapter extends RecyclerView.Adapter { +public class ExploreIssuesAdapter extends RecyclerView.Adapter { private final List searchedList; private final Context context; private final TinyDB tinyDb; - public SearchIssuesAdapter(List dataList, Context ctx) { + public ExploreIssuesAdapter(List dataList, Context ctx) { this.context = ctx; this.searchedList = dataList; @@ -49,7 +49,6 @@ public class SearchIssuesAdapter extends RecyclerView.Adapter { Context context = v.getContext(); - Intent intent = new Intent(context, IssueDetailActivity.class); intent.putExtra("issueNumber", issue.getNumber()); @@ -90,13 +88,11 @@ public class SearchIssuesAdapter extends RecyclerView.Adapter { +public class ExplorePublicOrganizationsAdapter extends RecyclerView.Adapter { private final Context context; private final int TYPE_LOAD = 0; @@ -31,7 +31,7 @@ public class PublicOrganizationsAdapter extends RecyclerView.Adapter organizationsListMain) { + public ExplorePublicOrganizationsAdapter(Context ctx, List organizationsListMain) { this.context = ctx; this.organizationsList = organizationsListMain; } @@ -41,10 +41,10 @@ public class PublicOrganizationsAdapter extends RecyclerView.Adapter call; - call = RetrofitClient.getApiInterface(context).checkRepoWatchStatus(token, repoOwner, repoName); call.enqueue(new Callback() { - @Override public void onResponse(@NonNull Call call, @NonNull retrofit2.Response response) { if(response.isSuccessful()) { - assert response.body() != null; tinyDb.putBoolean("repoWatch", response.body().getSubscribed()); - - } else { - - tinyDb.putBoolean("repoWatch", false); - - if(response.code() != 404) { - - Toasty.error(context, context.getString(R.string.genericApiStatusError)); - - } - } - + else { + tinyDb.putBoolean("repoWatch", false); + if(response.code() != 404) { + Toasty.error(context, context.getString(R.string.genericApiStatusError)); + } + } } @Override public void onFailure(@NonNull Call call, @NonNull Throwable t) { - tinyDb.putBoolean("repoWatch", false); Toasty.error(context, context.getString(R.string.genericApiStatusError)); } }); - } - context.startActivity(intent); }); diff --git a/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java index a8dccb58..0ead649f 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java @@ -50,6 +50,7 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter issuesComments; private final FragmentManager fragmentManager; private final BottomSheetReplyFragment.OnInteractedListener onInteractedListener; + private final Locale locale; public IssueCommentsAdapter(Context ctx, Bundle bundle, List issuesCommentsMain, FragmentManager fragmentManager, BottomSheetReplyFragment.OnInteractedListener onInteractedListener) { @@ -58,8 +59,8 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter { - tinyDB.putBoolean("commentEdited", true); onInteractedListener.onInteracted(); dialog.dismiss(); - }); linearLayout.addView(reactionSpinner); commentMenuEdit.setOnClickListener(v1 -> { - Bundle bundle = new Bundle(); bundle.putInt("commentId", issueComment.getId()); bundle.putString("commentAction", "edit"); @@ -141,11 +139,9 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter { - // get comment Url CharSequence commentUrl = issueComment.getHtml_url(); @@ -158,11 +154,9 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter { - // comment Url CharSequence commentUrl = issueComment.getHtml_url(); @@ -174,23 +168,19 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter { - StringBuilder stringBuilder = new StringBuilder(); String commenterName = issueComment.getUser().getUsername(); if(!commenterName.equals(tinyDB.getString("userLogin"))) { - stringBuilder.append("@").append(commenterName).append("\n\n"); } String[] lines = issueComment.getBody().split("\\R"); for(String line : lines) { - stringBuilder.append(">").append(line).append("\n"); } @@ -202,11 +192,9 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter { - ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE); assert clipboard != null; @@ -215,14 +203,11 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter { - deleteIssueComment(ctx, issueComment.getId(), getAdapterPosition()); dialog.dismiss(); - }); }); @@ -230,12 +215,9 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter { Context context = loginId.getContext(); - AppUtil.copyToClipboard(context, userLoginId, context.getString(R.string.copyLoginIdToClipBoard, userLoginId)); }); - } - } private void updateAdapter(int position) { @@ -243,7 +225,6 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter TimeHelper.customDateFormatForToastDateFormat(issueComment.getCreated_at())); - } else if(timeFormat.equals("normal")) { - - informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreated_at(), context.getResources().getConfiguration().locale, "normal", context)); + informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreated_at(), locale, "normal", context)); } if(!issueComment.getCreated_at().equals(issueComment.getUpdated_at())) { @@ -374,7 +352,6 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter void bindData(Issues issue) { TinyDB tinyDb = TinyDB.getInstance(context); - String locale = context.getResources().getConfiguration().locale.getLanguage(); + Locale locale = context.getResources().getConfiguration().locale; String timeFormat = tinyDb.getString("dateFormat"); int imgRadius = AppUtil.getPixelsFromDensity(context, 3); @@ -156,20 +156,20 @@ public class IssuesAdapter extends RecyclerView.Adapter switch(timeFormat) { case "pretty": { - PrettyTime prettyTime = new PrettyTime(new Locale(locale)); + PrettyTime prettyTime = new PrettyTime(locale); String createdTime = prettyTime.format(issue.getCreated_at()); this.issueCreatedTime.setText(createdTime); this.issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issue.getCreated_at()), context)); break; } case "normal": { - DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale)); + DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale); String createdTime = formatter.format(issue.getCreated_at()); this.issueCreatedTime.setText(createdTime); break; } case "normal1": { - DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale)); + DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + context.getResources().getString(R.string.timeAtText) + "' HH:mm", locale); String createdTime = formatter.format(issue.getCreated_at()); this.issueCreatedTime.setText(createdTime); break; diff --git a/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java index 78902648..e8801a6d 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java @@ -190,7 +190,7 @@ public class MyReposListAdapter extends RecyclerView.Adapter { - requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit(); - Objects.requireNonNull(((MainActivity) requireActivity()).getSupportActionBar()).show(); - }); - - OnBackPressedCallback callback = new OnBackPressedCallback(true) { - @Override - public void handleOnBackPressed() { - requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit(); - Objects.requireNonNull(((MainActivity) requireActivity()).getSupportActionBar()).show(); - } - }; - requireActivity().getOnBackPressedDispatcher().addCallback(getViewLifecycleOwner(), callback); - - viewBinding.donationLinkPatreon.setOnClickListener(v12 -> { - - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_VIEW); - intent.addCategory(Intent.CATEGORY_BROWSABLE); - intent.setData(Uri.parse(getResources().getString(R.string.supportLinkPatreon))); - startActivity(intent); - }); - - viewBinding.translateLink.setOnClickListener(v13 -> { - - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_VIEW); - intent.addCategory(Intent.CATEGORY_BROWSABLE); - intent.setData(Uri.parse(getResources().getString(R.string.crowdInLink))); - startActivity(intent); - }); - - viewBinding.appWebsite.setOnClickListener(v14 -> { - - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_VIEW); - intent.addCategory(Intent.CATEGORY_BROWSABLE); - intent.setData(Uri.parse(getResources().getString(R.string.appWebsiteLink))); - startActivity(intent); - }); - - if(AppUtil.isPro(requireContext())) { - - viewBinding.supportHeader.setVisibility(View.GONE); - viewBinding.dividerSupport.setVisibility(View.GONE); - viewBinding.donationLinkPatreon.setVisibility(View.GONE); - } - - return viewBinding.getRoot(); - } - -} diff --git a/app/src/main/java/org/mian/gitnex/fragments/ExploreIssuesFragment.java b/app/src/main/java/org/mian/gitnex/fragments/ExploreIssuesFragment.java index 180a8a90..47b414c4 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/ExploreIssuesFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/ExploreIssuesFragment.java @@ -13,7 +13,7 @@ import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import org.gitnex.tea4j.models.Issues; -import org.mian.gitnex.adapters.SearchIssuesAdapter; +import org.mian.gitnex.adapters.ExploreIssuesAdapter; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.databinding.FragmentSearchIssuesBinding; import org.mian.gitnex.helpers.AppUtil; @@ -33,7 +33,7 @@ import retrofit2.Response; public class ExploreIssuesFragment extends Fragment { private FragmentSearchIssuesBinding viewBinding; - private SearchIssuesAdapter adapter; + private ExploreIssuesAdapter adapter; private List dataList; Context ctx; @@ -48,7 +48,7 @@ public class ExploreIssuesFragment extends Fragment { ctx = getContext(); dataList = new ArrayList<>(); - adapter = new SearchIssuesAdapter(dataList, ctx); + adapter = new ExploreIssuesAdapter(dataList, ctx); LinearLayoutManager linearLayoutManager = new LinearLayoutManager(ctx); diff --git a/app/src/main/java/org/mian/gitnex/fragments/ExplorePublicOrganizationsFragment.java b/app/src/main/java/org/mian/gitnex/fragments/ExplorePublicOrganizationsFragment.java index d49de8b1..27a60b71 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/ExplorePublicOrganizationsFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/ExplorePublicOrganizationsFragment.java @@ -15,7 +15,7 @@ import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import org.gitnex.tea4j.models.Organization; import org.mian.gitnex.R; -import org.mian.gitnex.adapters.PublicOrganizationsAdapter; +import org.mian.gitnex.adapters.ExplorePublicOrganizationsAdapter; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.databinding.FragmentOrganizationsBinding; import org.mian.gitnex.helpers.Authorization; @@ -37,7 +37,7 @@ public class ExplorePublicOrganizationsFragment extends Fragment { private FragmentOrganizationsBinding fragmentPublicOrgBinding; private List organizationsList; - private PublicOrganizationsAdapter adapter; + private ExplorePublicOrganizationsAdapter adapter; private Context context; private int pageSize; private final String TAG = Constants.publicOrganizations; @@ -68,7 +68,7 @@ public class ExplorePublicOrganizationsFragment extends Fragment { adapter.notifyDataChanged(); }, 200)); - adapter = new PublicOrganizationsAdapter(getContext(), organizationsList); + adapter = new ExplorePublicOrganizationsAdapter(getContext(), organizationsList); adapter.setLoadMoreListener(() -> fragmentPublicOrgBinding.recyclerView.post(() -> { if(organizationsList.size() == resultLimit || pageSize == resultLimit) { int page = (organizationsList.size() + resultLimit) / resultLimit; diff --git a/app/src/main/java/org/mian/gitnex/fragments/ExploreRepositoriesFragment.java b/app/src/main/java/org/mian/gitnex/fragments/ExploreRepositoriesFragment.java index e09cbb05..980edc01 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/ExploreRepositoriesFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/ExploreRepositoriesFragment.java @@ -261,54 +261,21 @@ public class ExploreRepositoriesFragment extends Fragment { dialogFilterOptions.setContentView(view); filterBinding.includeTopic.setOnClickListener(includeTopic -> { - - if(filterBinding.includeTopic.isChecked()) { - - tinyDb.putBoolean("exploreRepoIncludeTopic", true); - } - else { - - tinyDb.putBoolean("exploreRepoIncludeTopic", false); - } + tinyDb.putBoolean("exploreRepoIncludeTopic", filterBinding.includeTopic.isChecked()); }); filterBinding.includeDesc.setOnClickListener(includeDesc -> { - - if(filterBinding.includeDesc.isChecked()) { - - tinyDb.putBoolean("exploreRepoIncludeDescription", true); - } - else { - - tinyDb.putBoolean("exploreRepoIncludeDescription", false); - } + tinyDb.putBoolean("exploreRepoIncludeDescription", filterBinding.includeDesc.isChecked()); }); filterBinding.includeTemplate.setOnClickListener(includeTemplate -> { - - if(filterBinding.includeTemplate.isChecked()) { - - tinyDb.putBoolean("exploreRepoIncludeTemplate", true); - } - else { - - tinyDb.putBoolean("exploreRepoIncludeTemplate", false); - } + tinyDb.putBoolean("exploreRepoIncludeTemplate", filterBinding.includeTemplate.isChecked()); }); filterBinding.onlyArchived.setOnClickListener(onlyArchived -> { - - if(filterBinding.onlyArchived.isChecked()) { - - tinyDb.putBoolean("exploreRepoOnlyArchived", true); - } - else { - - tinyDb.putBoolean("exploreRepoOnlyArchived", false); - } + tinyDb.putBoolean("exploreRepoOnlyArchived", filterBinding.onlyArchived.isChecked()); }); - filterBinding.includeTopic.setChecked(tinyDb.getBoolean("exploreRepoIncludeTopic")); filterBinding.includeDesc.setChecked(tinyDb.getBoolean("exploreRepoIncludeDescription")); filterBinding.includeTemplate.setChecked(tinyDb.getBoolean("exploreRepoIncludeTemplate")); diff --git a/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java b/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java index 3f14691d..64a62304 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java @@ -42,6 +42,7 @@ public class RepoInfoFragment extends Fragment { private LinearLayout pageContent; private static final String repoNameF = "param2"; private static final String repoOwnerF = "param1"; + private Locale locale; private FragmentRepoInfoBinding binding; @@ -74,17 +75,16 @@ public class RepoInfoFragment extends Fragment { public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentRepoInfoBinding.inflate(inflater, container, false); - TinyDB tinyDb = TinyDB.getInstance(getContext()); - ctx = getContext(); + locale = getResources().getConfiguration().locale; pageContent = binding.repoInfoLayout; pageContent.setVisibility(View.GONE); binding.repoMetaFrame.setVisibility(View.GONE); - getRepoInfo(Authorization.get(getContext()), repoOwner, repoName, getResources().getConfiguration().locale, tinyDb.getString("dateFormat")); + getRepoInfo(Authorization.get(getContext()), repoOwner, repoName, locale, tinyDb.getString("dateFormat")); getFileContents(Authorization.get(getContext()), repoOwner, repoName, getResources().getString(R.string.defaultFilename)); if(isExpandViewVisible()) { @@ -173,7 +173,7 @@ public class RepoInfoFragment extends Fragment { return binding.repoMetaFrame.getVisibility() == View.VISIBLE; } - private void getRepoInfo(String token, final String owner, String repo, final Locale locale, final String timeFormat) { + private void getRepoInfo(String token, final String owner, String repo, Locale locale, final String timeFormat) { final TinyDB tinyDb = TinyDB.getInstance(getContext()); diff --git a/app/src/main/java/org/mian/gitnex/fragments/SettingsFragment.java b/app/src/main/java/org/mian/gitnex/fragments/SettingsFragment.java index 68603d59..4541e9a4 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/SettingsFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/SettingsFragment.java @@ -1,8 +1,11 @@ package org.mian.gitnex.fragments; +import android.app.Dialog; import android.content.ActivityNotFoundException; import android.content.Context; import android.content.Intent; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; import android.net.Uri; import android.os.Bundle; import android.view.LayoutInflater; @@ -20,7 +23,9 @@ import org.mian.gitnex.activities.SettingsNotificationsActivity; import org.mian.gitnex.activities.SettingsReportsActivity; import org.mian.gitnex.activities.SettingsSecurityActivity; import org.mian.gitnex.activities.SettingsTranslationActivity; +import org.mian.gitnex.databinding.CustomAboutDialogBinding; import org.mian.gitnex.databinding.FragmentSettingsBinding; +import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Version; @@ -32,6 +37,7 @@ public class SettingsFragment extends Fragment { private Context ctx; private TinyDB tinyDB; + private Dialog aboutAppDialog; @Nullable @Override @@ -41,6 +47,7 @@ public class SettingsFragment extends Fragment { ctx = getContext(); tinyDB = TinyDB.getInstance(ctx); + aboutAppDialog = new Dialog(ctx); ((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.navSettings)); @@ -63,37 +70,78 @@ public class SettingsFragment extends Fragment { fragmentSettingsBinding.reportsFrame.setOnClickListener(v1 -> startActivity(new Intent(ctx, SettingsReportsActivity.class))); - fragmentSettingsBinding.rateAppFrame.setOnClickListener(aboutApp -> rateThisApp()); + fragmentSettingsBinding.rateAppFrame.setOnClickListener(rateApp -> rateThisApp()); - fragmentSettingsBinding.aboutAppFrame.setOnClickListener(aboutApp -> requireActivity().getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AboutFragment()).commit()); + fragmentSettingsBinding.aboutAppFrame.setOnClickListener(aboutApp -> showAboutAppDialog()); return fragmentSettingsBinding.getRoot(); + } + public void showAboutAppDialog() { + + if (aboutAppDialog.getWindow() != null) { + aboutAppDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + } + + CustomAboutDialogBinding aboutAppDialogBinding = CustomAboutDialogBinding.inflate(LayoutInflater.from(ctx)); + View view = aboutAppDialogBinding.getRoot(); + aboutAppDialog.setContentView(view); + + aboutAppDialogBinding.appVersionBuild.setText(getString(R.string.appVersionBuild, AppUtil.getAppVersion(ctx), AppUtil.getAppBuildNo(ctx))); + aboutAppDialogBinding.userServerVersion.setText(tinyDB.getString("giteaVersion")); + + aboutAppDialogBinding.donationLinkPatreon.setOnClickListener(v12 -> { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + intent.setData(Uri.parse(getResources().getString(R.string.supportLinkPatreon))); + startActivity(intent); + }); + + aboutAppDialogBinding.translateLink.setOnClickListener(v13 -> { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + intent.setData(Uri.parse(getResources().getString(R.string.crowdInLink))); + startActivity(intent); + }); + + aboutAppDialogBinding.appWebsite.setOnClickListener(v14 -> { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + intent.addCategory(Intent.CATEGORY_BROWSABLE); + intent.setData(Uri.parse(getResources().getString(R.string.appWebsiteLink))); + startActivity(intent); + }); + + if(AppUtil.isPro(requireContext())) { + aboutAppDialogBinding.supportHeader.setVisibility(View.GONE); + aboutAppDialogBinding.dividerSupport.setVisibility(View.GONE); + aboutAppDialogBinding.donationLinkPatreon.setVisibility(View.GONE); + } + + aboutAppDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); + aboutAppDialog.show(); } public void rateThisApp() { try { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + requireActivity().getPackageName()))); } catch(ActivityNotFoundException e) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + requireActivity().getPackageName()))); } } @Override public void onResume() { - super.onResume(); if(tinyDB.getBoolean("refreshParent")) { - requireActivity().recreate(); requireActivity().overridePendingTransition(0, 0); tinyDB.putBoolean("refreshParent", false); } } - } diff --git a/app/src/main/java/org/mian/gitnex/helpers/ssl/MemorizingTrustManager.java b/app/src/main/java/org/mian/gitnex/helpers/ssl/MemorizingTrustManager.java index cc5161c0..78db04ec 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/ssl/MemorizingTrustManager.java +++ b/app/src/main/java/org/mian/gitnex/helpers/ssl/MemorizingTrustManager.java @@ -424,16 +424,16 @@ public class MemorizingTrustManager implements X509TrustManager { } } - private static void certDetails(StringBuilder stringBuilder, X509Certificate c) { + private void certDetails(StringBuilder stringBuilder, X509Certificate c) { - SimpleDateFormat validityDateFormater = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()); + SimpleDateFormat validityDateFormatter = new SimpleDateFormat("yyyy-MM-dd", context.getResources().getConfiguration().locale); stringBuilder.append("\n") .append(c.getSubjectDN().toString()) .append("\n") - .append(validityDateFormater.format(c.getNotBefore())) + .append(validityDateFormatter.format(c.getNotBefore())) .append(" - ") - .append(validityDateFormater.format(c.getNotAfter())) + .append(validityDateFormatter.format(c.getNotAfter())) .append("\nSHA-256: ") .append(certHash(c, "SHA-256")) .append("\nSHA-1: ") diff --git a/app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java b/app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java index aa6eabb0..9a6cb1f3 100644 --- a/app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java +++ b/app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java @@ -42,39 +42,23 @@ public class FilesViewModel extends ViewModel { .getFiles(token, owner, repo, ref); call.enqueue(new Callback>() { - @Override public void onResponse(@NonNull Call> call, @NonNull Response> response) { - if (response.code() == 200) { - - assert response.body() != null; - - if(response.body().size() > 0) { - - Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); - filesList.postValue(response.body()); - } - else { - - progressBar.setVisibility(View.GONE); - noDataFiles.setVisibility(View.VISIBLE); - } + if(response.isSuccessful() && response.body() != null && !response.body().isEmpty()) { + Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); + filesList.postValue(response.body()); } else { - progressBar.setVisibility(View.GONE); noDataFiles.setVisibility(View.VISIBLE); } - } @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { - Toasty.error(ctx, ctx.getString(R.string.errorOnLogin)); } - }); } @@ -93,27 +77,14 @@ public class FilesViewModel extends ViewModel { .getDirFiles(token, owner, repo, filesDir, ref); call.enqueue(new Callback>() { - @Override public void onResponse(@NonNull Call> call, @NonNull Response> response) { - if (response.code() == 200) { - - assert response.body() != null; - - if(response.body().size() > 0) { - - Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); - filesList2.postValue(response.body()); - } - else { - - progressBar.setVisibility(View.GONE); - noDataFiles.setVisibility(View.VISIBLE); - } + if(response.isSuccessful() && response.body() != null && !response.body().isEmpty()) { + Collections.sort(response.body(), (byType1, byType2) -> byType1.getType().compareTo(byType2.getType())); + filesList2.postValue(response.body()); } else { - progressBar.setVisibility(View.GONE); noDataFiles.setVisibility(View.VISIBLE); } @@ -121,10 +92,8 @@ public class FilesViewModel extends ViewModel { @Override public void onFailure(@NonNull Call> call, @NonNull Throwable t) { - Toasty.error(ctx, ctx.getString(R.string.errorOnLogin)); } - }); } diff --git a/app/src/main/res/layout/custom_about_dialog.xml b/app/src/main/res/layout/custom_about_dialog.xml new file mode 100644 index 00000000..73be47b3 --- /dev/null +++ b/app/src/main/res/layout/custom_about_dialog.xml @@ -0,0 +1,205 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +