From ca37ad661d36dd1ecbb48a7b790f2d4581580d37 Mon Sep 17 00:00:00 2001 From: M M Arif Date: Wed, 1 Apr 2020 11:38:14 +0500 Subject: [PATCH 1/4] Changed repos list menus to bottom sheets --- .../adapters/ExploreRepositoriesAdapter.java | 104 +++++++---------- .../gitnex/adapters/MyReposListAdapter.java | 101 +++++++---------- .../gitnex/adapters/ReposListAdapter.java | 106 +++++++----------- .../adapters/RepositoriesByOrgAdapter.java | 101 +++++++---------- .../adapters/StarredReposListAdapter.java | 102 +++++++---------- .../bottom_sheet_repository_in_list.xml | 60 ++++++++++ .../main/res/menu/repo_dotted_list_menu.xml | 19 ---- 7 files changed, 258 insertions(+), 335 deletions(-) create mode 100644 app/src/main/res/layout/bottom_sheet_repository_in_list.xml delete mode 100644 app/src/main/res/menu/repo_dotted_list_menu.xml diff --git a/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java index e179e07b..98424c34 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java @@ -1,19 +1,19 @@ package org.mian.gitnex.adapters; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.widget.PopupMenu; import androidx.recyclerview.widget.RecyclerView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; +import com.google.android.material.bottomsheet.BottomSheetDialog; import com.squareup.picasso.Picasso; import org.mian.gitnex.R; import org.mian.gitnex.activities.OpenRepoInBrowserActivity; @@ -23,9 +23,7 @@ import org.mian.gitnex.activities.RepoWatchersActivity; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.models.UserRepositories; import org.mian.gitnex.util.TinyDB; -import java.lang.reflect.Field; import java.util.List; -import java.util.Objects; /** * Author M M Arif @@ -66,85 +64,63 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter { - Context context = v.getContext(); - TextView repoFullName = v.findViewById(R.id.repoFullName); + Context context = v.getContext(); + TextView repoFullName = v.findViewById(R.id.repoFullName); - Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", repoFullName.getText().toString()); + Intent intent = new Intent(context, RepoDetailActivity.class); + intent.putExtra("repoFullName", repoFullName.getText().toString()); - TinyDB tinyDb = new TinyDB(context); - tinyDb.putString("repoFullName", repoFullName.getText().toString()); - tinyDb.putBoolean("resumeIssues", true); - context.startActivity(intent); + TinyDB tinyDb = new TinyDB(context); + tinyDb.putString("repoFullName", repoFullName.getText().toString()); + tinyDb.putBoolean("resumeIssues", true); + context.startActivity(intent); - } }); - reposDropdownMenu.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + reposDropdownMenu.setOnClickListener(v -> { - final Context context = v.getContext(); - //Context context_ = new ContextThemeWrapper(context, R.style.popupMenuStyle); + final Context context = v.getContext(); - PopupMenu popupMenu = new PopupMenu(context, v); - popupMenu.inflate(R.menu.repo_dotted_list_menu); + @SuppressLint("InflateParams") + View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - Object menuHelper; - Class[] argTypes; - try { + TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); + TextView repoStargazers = view.findViewById(R.id.repoStargazers); + TextView repoWatchers = view.findViewById(R.id.repoWatchers); - Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup"); - fMenuHelper.setAccessible(true); - menuHelper = fMenuHelper.get(popupMenu); - argTypes = new Class[] { boolean.class }; - Objects.requireNonNull(menuHelper).getClass().getDeclaredMethod("setForceShowIcon", - argTypes).invoke(menuHelper, true); + BottomSheetDialog dialog = new BottomSheetDialog(context); + dialog.setContentView(view); + dialog.show(); - } catch (Exception e) { + repoOpenInBrowser.setOnClickListener(openInBrowser -> { - popupMenu.show(); - return; + Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); + intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); + context.startActivity(intentOpenInBrowser); + dialog.dismiss(); - } + }); - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.repoStargazers: + repoStargazers.setOnClickListener(openInBrowser -> { - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullName.getText()); - context.startActivity(intent); - break; + Intent intent = new Intent(context, RepoStargazersActivity.class); + intent.putExtra("repoFullNameForStars", fullName.getText()); + context.startActivity(intent); + dialog.dismiss(); - case R.id.repoWatchers: + }); - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullName.getText()); - context.startActivity(intentW); - break; + repoWatchers.setOnClickListener(openInBrowser -> { - case R.id.repoOpenInBrowser: + Intent intentW = new Intent(context, RepoWatchersActivity.class); + intentW.putExtra("repoFullNameForWatchers", fullName.getText()); + context.startActivity(intentW); + dialog.dismiss(); - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); - context.startActivity(intentOpenInBrowser); - break; - - } - return false; - } - }); - - popupMenu.show(); - - } + }); + }); } 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 6f2d7833..de8ce9d1 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java @@ -1,10 +1,10 @@ package org.mian.gitnex.adapters; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Filter; @@ -13,6 +13,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; +import com.google.android.material.bottomsheet.BottomSheetDialog; import com.squareup.picasso.Picasso; import org.mian.gitnex.R; import org.mian.gitnex.activities.OpenRepoInBrowserActivity; @@ -22,11 +23,9 @@ import org.mian.gitnex.activities.RepoWatchersActivity; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.models.UserRepositories; import org.mian.gitnex.util.TinyDB; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; -import androidx.appcompat.widget.PopupMenu; import androidx.recyclerview.widget.RecyclerView; /** @@ -64,85 +63,63 @@ public class MyReposListAdapter extends RecyclerView.Adapter { - Context context = v.getContext(); + Context context = v.getContext(); - Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", fullNameMy.getText().toString()); + Intent intent = new Intent(context, RepoDetailActivity.class); + intent.putExtra("repoFullName", fullNameMy.getText().toString()); - TinyDB tinyDb = new TinyDB(context); - tinyDb.putString("repoFullName", fullNameMy.getText().toString()); - tinyDb.putString("repoType", repoType.getText().toString()); - tinyDb.putBoolean("resumeIssues", true); - context.startActivity(intent); + TinyDB tinyDb = new TinyDB(context); + tinyDb.putString("repoFullName", fullNameMy.getText().toString()); + tinyDb.putString("repoType", repoType.getText().toString()); + tinyDb.putBoolean("resumeIssues", true); + context.startActivity(intent); - } }); - reposDropdownMenu.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + reposDropdownMenu.setOnClickListener(v -> { - final Context context = v.getContext(); - //Context context_ = new ContextThemeWrapper(context, R.style.popupMenuStyle); + final Context context = v.getContext(); - PopupMenu popupMenu = new PopupMenu(context, v); - popupMenu.inflate(R.menu.repo_dotted_list_menu); + @SuppressLint("InflateParams") + View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - Object menuHelper; - Class[] argTypes; - try { + TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); + TextView repoStargazers = view.findViewById(R.id.repoStargazers); + TextView repoWatchers = view.findViewById(R.id.repoWatchers); - Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup"); - fMenuHelper.setAccessible(true); - menuHelper = fMenuHelper.get(popupMenu); - argTypes = new Class[] { boolean.class }; - menuHelper.getClass().getDeclaredMethod("setForceShowIcon", - argTypes).invoke(menuHelper, true); + BottomSheetDialog dialog = new BottomSheetDialog(context); + dialog.setContentView(view); + dialog.show(); - } catch (Exception e) { + repoOpenInBrowser.setOnClickListener(openInBrowser -> { - popupMenu.show(); - return; + Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); + intentOpenInBrowser.putExtra("repoFullNameBrowser", fullNameMy.getText()); + context.startActivity(intentOpenInBrowser); + dialog.dismiss(); - } + }); - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.repoStargazers: + repoStargazers.setOnClickListener(openInBrowser -> { - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullNameMy.getText()); - context.startActivity(intent); - break; + Intent intent = new Intent(context, RepoStargazersActivity.class); + intent.putExtra("repoFullNameForStars", fullNameMy.getText()); + context.startActivity(intent); + dialog.dismiss(); - case R.id.repoWatchers: + }); - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullNameMy.getText()); - context.startActivity(intentW); - break; + repoWatchers.setOnClickListener(openInBrowser -> { - case R.id.repoOpenInBrowser: + Intent intentW = new Intent(context, RepoWatchersActivity.class); + intentW.putExtra("repoFullNameForWatchers", fullNameMy.getText()); + context.startActivity(intentW); + dialog.dismiss(); - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullNameMy.getText()); - context.startActivity(intentOpenInBrowser); - break; + }); - } - return false; - } - }); - - popupMenu.show(); - - } }); } diff --git a/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java index 4eb33545..ad444b8a 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java @@ -1,13 +1,12 @@ package org.mian.gitnex.adapters; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; import androidx.annotation.NonNull; -import androidx.appcompat.widget.PopupMenu; import androidx.recyclerview.widget.RecyclerView; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Filter; @@ -16,6 +15,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; +import com.google.android.material.bottomsheet.BottomSheetDialog; import com.squareup.picasso.Picasso; import org.mian.gitnex.R; import org.mian.gitnex.activities.OpenRepoInBrowserActivity; @@ -25,7 +25,6 @@ import org.mian.gitnex.activities.RepoWatchersActivity; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.models.UserRepositories; import org.mian.gitnex.util.TinyDB; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; @@ -65,88 +64,65 @@ public class ReposListAdapter extends RecyclerView.Adapter { - Context context = v.getContext(); - TextView repoFullName = v.findViewById(R.id.repoFullName); - TextView repoType_ = v.findViewById(R.id.repoType); + Context context = v.getContext(); + TextView repoFullName = v.findViewById(R.id.repoFullName); + TextView repoType_ = v.findViewById(R.id.repoType); - Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", repoFullName.getText().toString()); + Intent intent = new Intent(context, RepoDetailActivity.class); + intent.putExtra("repoFullName", repoFullName.getText().toString()); - TinyDB tinyDb = new TinyDB(context); - tinyDb.putString("repoFullName", repoFullName.getText().toString()); - tinyDb.putString("repoType", repoType_.getText().toString()); - tinyDb.putBoolean("resumeIssues", true); - context.startActivity(intent); + TinyDB tinyDb = new TinyDB(context); + tinyDb.putString("repoFullName", repoFullName.getText().toString()); + tinyDb.putString("repoType", repoType_.getText().toString()); + tinyDb.putBoolean("resumeIssues", true); + context.startActivity(intent); - } }); - reposDropdownMenu.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + reposDropdownMenu.setOnClickListener(v -> { - final Context context = v.getContext(); - //Context context_ = new ContextThemeWrapper(context, R.style.popupMenuStyle); + final Context context = v.getContext(); - PopupMenu popupMenu = new PopupMenu(context, v); - popupMenu.inflate(R.menu.repo_dotted_list_menu); + @SuppressLint("InflateParams") + View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - Object menuHelper; - Class[] argTypes; - try { + TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); + TextView repoStargazers = view.findViewById(R.id.repoStargazers); + TextView repoWatchers = view.findViewById(R.id.repoWatchers); - Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup"); - fMenuHelper.setAccessible(true); - menuHelper = fMenuHelper.get(popupMenu); - argTypes = new Class[] { boolean.class }; - assert menuHelper != null; - menuHelper.getClass().getDeclaredMethod("setForceShowIcon", - argTypes).invoke(menuHelper, true); + BottomSheetDialog dialog = new BottomSheetDialog(context); + dialog.setContentView(view); + dialog.show(); - } catch (Exception e) { + repoOpenInBrowser.setOnClickListener(openInBrowser -> { - popupMenu.show(); - return; + Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); + intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); + context.startActivity(intentOpenInBrowser); + dialog.dismiss(); - } + }); - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.repoStargazers: + repoStargazers.setOnClickListener(openInBrowser -> { - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullName.getText()); - context.startActivity(intent); - break; + Intent intent = new Intent(context, RepoStargazersActivity.class); + intent.putExtra("repoFullNameForStars", fullName.getText()); + context.startActivity(intent); + dialog.dismiss(); - case R.id.repoWatchers: + }); - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullName.getText()); - context.startActivity(intentW); - break; + repoWatchers.setOnClickListener(openInBrowser -> { - case R.id.repoOpenInBrowser: + Intent intentW = new Intent(context, RepoWatchersActivity.class); + intentW.putExtra("repoFullNameForWatchers", fullName.getText()); + context.startActivity(intentW); + dialog.dismiss(); - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); - context.startActivity(intentOpenInBrowser); - break; + }); - } - return false; - } - }); - - popupMenu.show(); - - } }); } diff --git a/app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java index fe460773..9b44ed7d 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java @@ -1,10 +1,10 @@ package org.mian.gitnex.adapters; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Filter; @@ -13,6 +13,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; +import com.google.android.material.bottomsheet.BottomSheetDialog; import com.squareup.picasso.Picasso; import org.mian.gitnex.R; import org.mian.gitnex.activities.OpenRepoInBrowserActivity; @@ -22,11 +23,9 @@ import org.mian.gitnex.activities.RepoWatchersActivity; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.models.UserRepositories; import org.mian.gitnex.util.TinyDB; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; -import androidx.appcompat.widget.PopupMenu; import androidx.recyclerview.widget.RecyclerView; /** @@ -64,85 +63,63 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter { - Context context = v.getContext(); + Context context = v.getContext(); - Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", fullName.getText().toString()); + Intent intent = new Intent(context, RepoDetailActivity.class); + intent.putExtra("repoFullName", fullName.getText().toString()); - TinyDB tinyDb = new TinyDB(context); - tinyDb.putString("repoFullName", fullName.getText().toString()); - tinyDb.putString("repoType", repoType.getText().toString()); - tinyDb.putBoolean("resumeIssues", true); - context.startActivity(intent); + TinyDB tinyDb = new TinyDB(context); + tinyDb.putString("repoFullName", fullName.getText().toString()); + tinyDb.putString("repoType", repoType.getText().toString()); + tinyDb.putBoolean("resumeIssues", true); + context.startActivity(intent); - } }); - reposDropdownMenu.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + reposDropdownMenu.setOnClickListener(v -> { - final Context context = v.getContext(); - //Context context_ = new ContextThemeWrapper(context, R.style.popupMenuStyle); + final Context context = v.getContext(); - PopupMenu popupMenu = new PopupMenu(context, v); - popupMenu.inflate(R.menu.repo_dotted_list_menu); + @SuppressLint("InflateParams") + View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - Object menuHelper; - Class[] argTypes; - try { + TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); + TextView repoStargazers = view.findViewById(R.id.repoStargazers); + TextView repoWatchers = view.findViewById(R.id.repoWatchers); - Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup"); - fMenuHelper.setAccessible(true); - menuHelper = fMenuHelper.get(popupMenu); - argTypes = new Class[] { boolean.class }; - menuHelper.getClass().getDeclaredMethod("setForceShowIcon", - argTypes).invoke(menuHelper, true); + BottomSheetDialog dialog = new BottomSheetDialog(context); + dialog.setContentView(view); + dialog.show(); - } catch (Exception e) { + repoOpenInBrowser.setOnClickListener(openInBrowser -> { - popupMenu.show(); - return; + Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); + intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); + context.startActivity(intentOpenInBrowser); + dialog.dismiss(); - } + }); - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.repoStargazers: + repoStargazers.setOnClickListener(openInBrowser -> { - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullName.getText()); - context.startActivity(intent); - break; + Intent intent = new Intent(context, RepoStargazersActivity.class); + intent.putExtra("repoFullNameForStars", fullName.getText()); + context.startActivity(intent); + dialog.dismiss(); - case R.id.repoWatchers: + }); - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullName.getText()); - context.startActivity(intentW); - break; + repoWatchers.setOnClickListener(openInBrowser -> { - case R.id.repoOpenInBrowser: + Intent intentW = new Intent(context, RepoWatchersActivity.class); + intentW.putExtra("repoFullNameForWatchers", fullName.getText()); + context.startActivity(intentW); + dialog.dismiss(); - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); - context.startActivity(intentOpenInBrowser); - break; + }); - } - return false; - } - }); - - popupMenu.show(); - - } }); } diff --git a/app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java index 8ce1183b..7695158c 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/StarredReposListAdapter.java @@ -1,10 +1,10 @@ package org.mian.gitnex.adapters; +import android.annotation.SuppressLint; import android.content.Context; import android.content.Intent; import android.graphics.Typeface; import android.view.LayoutInflater; -import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.Filter; @@ -13,6 +13,7 @@ import android.widget.ImageView; import android.widget.TextView; import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; +import com.google.android.material.bottomsheet.BottomSheetDialog; import com.squareup.picasso.Picasso; import org.mian.gitnex.R; import org.mian.gitnex.activities.OpenRepoInBrowserActivity; @@ -22,12 +23,9 @@ import org.mian.gitnex.activities.RepoWatchersActivity; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.models.UserRepositories; import org.mian.gitnex.util.TinyDB; -import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import androidx.annotation.NonNull; -import androidx.appcompat.view.ContextThemeWrapper; -import androidx.appcompat.widget.PopupMenu; import androidx.recyclerview.widget.RecyclerView; /** @@ -65,85 +63,63 @@ public class StarredReposListAdapter extends RecyclerView.Adapter { - Context context = v.getContext(); + Context context = v.getContext(); - Intent intent = new Intent(context, RepoDetailActivity.class); - intent.putExtra("repoFullName", fullName.getText().toString()); + Intent intent = new Intent(context, RepoDetailActivity.class); + intent.putExtra("repoFullName", fullName.getText().toString()); - TinyDB tinyDb = new TinyDB(context); - tinyDb.putString("repoFullName", fullName.getText().toString()); - tinyDb.putString("repoType", repoType.getText().toString()); - tinyDb.putBoolean("resumeIssues", true); - context.startActivity(intent); + TinyDB tinyDb = new TinyDB(context); + tinyDb.putString("repoFullName", fullName.getText().toString()); + tinyDb.putString("repoType", repoType.getText().toString()); + tinyDb.putBoolean("resumeIssues", true); + context.startActivity(intent); - } }); - reposDropdownMenu.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { + reposDropdownMenu.setOnClickListener(v -> { - final Context context = v.getContext(); - Context context_ = new ContextThemeWrapper(context, R.style.AppThemeConfirmDialog); + final Context context = v.getContext(); - PopupMenu popupMenu = new PopupMenu(context, v); - popupMenu.inflate(R.menu.repo_dotted_list_menu); + @SuppressLint("InflateParams") + View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null); - Object menuHelper; - Class[] argTypes; - try { + TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser); + TextView repoStargazers = view.findViewById(R.id.repoStargazers); + TextView repoWatchers = view.findViewById(R.id.repoWatchers); - Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup"); - fMenuHelper.setAccessible(true); - menuHelper = fMenuHelper.get(popupMenu); - argTypes = new Class[] { boolean.class }; - menuHelper.getClass().getDeclaredMethod("setForceShowIcon", - argTypes).invoke(menuHelper, true); + BottomSheetDialog dialog = new BottomSheetDialog(context); + dialog.setContentView(view); + dialog.show(); - } catch (Exception e) { + repoOpenInBrowser.setOnClickListener(openInBrowser -> { - popupMenu.show(); - return; + Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); + intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); + context.startActivity(intentOpenInBrowser); + dialog.dismiss(); - } + }); - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.repoStargazers: + repoStargazers.setOnClickListener(openInBrowser -> { - Intent intent = new Intent(context, RepoStargazersActivity.class); - intent.putExtra("repoFullNameForStars", fullName.getText()); - context.startActivity(intent); - break; + Intent intent = new Intent(context, RepoStargazersActivity.class); + intent.putExtra("repoFullNameForStars", fullName.getText()); + context.startActivity(intent); + dialog.dismiss(); - case R.id.repoWatchers: + }); - Intent intentW = new Intent(context, RepoWatchersActivity.class); - intentW.putExtra("repoFullNameForWatchers", fullName.getText()); - context.startActivity(intentW); - break; + repoWatchers.setOnClickListener(openInBrowser -> { - case R.id.repoOpenInBrowser: + Intent intentW = new Intent(context, RepoWatchersActivity.class); + intentW.putExtra("repoFullNameForWatchers", fullName.getText()); + context.startActivity(intentW); + dialog.dismiss(); - Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class); - intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText()); - context.startActivity(intentOpenInBrowser); - break; + }); - } - return false; - } - }); - - popupMenu.show(); - - } }); } diff --git a/app/src/main/res/layout/bottom_sheet_repository_in_list.xml b/app/src/main/res/layout/bottom_sheet_repository_in_list.xml new file mode 100644 index 00000000..e370244e --- /dev/null +++ b/app/src/main/res/layout/bottom_sheet_repository_in_list.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/repo_dotted_list_menu.xml b/app/src/main/res/menu/repo_dotted_list_menu.xml deleted file mode 100644 index b9dac84c..00000000 --- a/app/src/main/res/menu/repo_dotted_list_menu.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - \ No newline at end of file From 1e52649b7615a285727f6c5e4f32341a49c07acf Mon Sep 17 00:00:00 2001 From: M M Arif Date: Wed, 1 Apr 2020 14:44:38 +0500 Subject: [PATCH 2/4] Added to labels, issue comment --- .../adapters/ExploreRepositoriesAdapter.java | 8 +- .../gitnex/adapters/IssueCommentsAdapter.java | 41 ++++++++-- .../mian/gitnex/adapters/LabelsAdapter.java | 81 +++++++------------ .../gitnex/adapters/MyReposListAdapter.java | 6 +- .../gitnex/adapters/ReposListAdapter.java | 6 +- .../adapters/RepositoriesByOrgAdapter.java | 2 + .../adapters/StarredReposListAdapter.java | 6 +- .../layout/bottom_sheet_issue_comments.xml | 49 +++++++++++ .../layout/bottom_sheet_labels_in_list.xml | 60 ++++++++++++++ .../bottom_sheet_repository_in_list.xml | 12 +++ app/src/main/res/menu/issue_comment_menu.xml | 15 ---- app/src/main/res/menu/labels_menu.xml | 14 ---- 12 files changed, 206 insertions(+), 94 deletions(-) create mode 100644 app/src/main/res/layout/bottom_sheet_issue_comments.xml create mode 100644 app/src/main/res/layout/bottom_sheet_labels_in_list.xml delete mode 100644 app/src/main/res/menu/issue_comment_menu.xml delete mode 100644 app/src/main/res/menu/labels_menu.xml diff --git a/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java index 98424c34..22ff2ab8 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ExploreRepositoriesAdapter.java @@ -89,7 +89,9 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter { + repoStargazers.setOnClickListener(stargazers -> { Intent intent = new Intent(context, RepoStargazersActivity.class); intent.putExtra("repoFullNameForStars", fullName.getText()); @@ -112,7 +114,7 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter { + repoWatchers.setOnClickListener(watchers -> { Intent intentW = new Intent(context, RepoWatchersActivity.class); intentW.putExtra("repoFullNameForWatchers", fullName.getText()); @@ -120,7 +122,7 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter { + + final Context context = v.getContext(); + + @SuppressLint("InflateParams") + View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_issue_comments, null); + + TextView commentMenuEdit = view.findViewById(R.id.commentMenuEdit); + //TextView commentMenuDelete = view.findViewById(R.id.commentMenuDelete); + + BottomSheetDialog dialog = new BottomSheetDialog(context); + dialog.setContentView(view); + dialog.show(); + + commentMenuEdit.setOnClickListener(ediComment -> { + + Intent intent = new Intent(context, ReplyToIssueActivity.class); + intent.putExtra("commentId", commendId.getText()); + intent.putExtra("commentAction", "edit"); + intent.putExtra("commentBody", commendBodyRaw.getText()); + context.startActivity(intent); + dialog.dismiss(); + + }); + + /*commentMenuDelete.setOnClickListener(deleteComment -> { + + dialog.dismiss(); + + });*/ + + }); + + /*commentsOptionsMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -137,7 +168,7 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter { - final Context context = v.getContext(); - //Context context_ = new ContextThemeWrapper(context, R.style.popupMenuStyle); + final Context context = v.getContext(); - PopupMenu popupMenu = new PopupMenu(context, v); - popupMenu.inflate(R.menu.labels_menu); + @SuppressLint("InflateParams") + View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_labels_in_list, null); - Object menuHelper; - Class[] argTypes; - try { + TextView labelMenuEdit = view.findViewById(R.id.labelMenuEdit); + TextView labelMenuDelete = view.findViewById(R.id.labelMenuDelete); + TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader); - Field fMenuHelper = PopupMenu.class.getDeclaredField("mPopup"); - fMenuHelper.setAccessible(true); - menuHelper = fMenuHelper.get(popupMenu); - argTypes = new Class[] { boolean.class }; - menuHelper.getClass().getDeclaredMethod("setForceShowIcon", - argTypes).invoke(menuHelper, true); + bottomSheetHeader.setText(labelTitle.getText()); + BottomSheetDialog dialog = new BottomSheetDialog(context); + dialog.setContentView(view); + dialog.show(); - } catch (Exception e) { + labelMenuEdit.setOnClickListener(editLabel -> { - popupMenu.show(); - return; + Intent intent = new Intent(context, CreateLabelActivity.class); + intent.putExtra("labelId", labelId.getText()); + intent.putExtra("labelTitle", labelTitle.getText()); + intent.putExtra("labelColor", labelColor.getText()); + intent.putExtra("labelAction", "edit"); + context.startActivity(intent); + dialog.dismiss(); - } + }); - popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { - switch (item.getItemId()) { - case R.id.labelMenuEdit: + labelMenuDelete.setOnClickListener(deleteLabel -> { - Intent intent = new Intent(context, CreateLabelActivity.class); - intent.putExtra("labelId", labelId.getText()); - intent.putExtra("labelTitle", labelTitle.getText()); - intent.putExtra("labelColor", labelColor.getText()); - intent.putExtra("labelAction", "edit"); - context.startActivity(intent); - break; + AlertDialogs.labelDeleteDialog(context, labelTitle.getText().toString(), labelId.getText().toString(), + context.getResources().getString(R.string.labelDeleteTitle), + context.getResources().getString(R.string.labelDeleteMessage), + context.getResources().getString(R.string.labelDeletePositiveButton), + context.getResources().getString(R.string.labelDeleteNegativeButton)); + dialog.dismiss(); - case R.id.labelMenuDelete: + }); - AlertDialogs.labelDeleteDialog(context, labelTitle.getText().toString(), labelId.getText().toString(), - context.getResources().getString(R.string.labelDeleteTitle), - context.getResources().getString(R.string.labelDeleteMessage), - context.getResources().getString(R.string.labelDeletePositiveButton), - context.getResources().getString(R.string.labelDeleteNegativeButton)); - break; - - } - return false; - } - }); - - popupMenu.show(); - - } }); } 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 de8ce9d1..3a339e06 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java @@ -88,7 +88,9 @@ public class MyReposListAdapter extends RecyclerView.Adapter { + repoStargazers.setOnClickListener(stargazers -> { Intent intent = new Intent(context, RepoStargazersActivity.class); intent.putExtra("repoFullNameForStars", fullNameMy.getText()); @@ -111,7 +113,7 @@ public class MyReposListAdapter extends RecyclerView.Adapter { + repoWatchers.setOnClickListener(watchers -> { Intent intentW = new Intent(context, RepoWatchersActivity.class); intentW.putExtra("repoFullNameForWatchers", fullNameMy.getText()); diff --git a/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java index ad444b8a..fce07051 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java @@ -91,7 +91,9 @@ public class ReposListAdapter extends RecyclerView.Adapter { + repoStargazers.setOnClickListener(stargazers -> { Intent intent = new Intent(context, RepoStargazersActivity.class); intent.putExtra("repoFullNameForStars", fullName.getText()); @@ -114,7 +116,7 @@ public class ReposListAdapter extends RecyclerView.Adapter { + repoWatchers.setOnClickListener(watchers -> { Intent intentW = new Intent(context, RepoWatchersActivity.class); intentW.putExtra("repoFullNameForWatchers", fullName.getText()); diff --git a/app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java index 9b44ed7d..c2521e4f 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/RepositoriesByOrgAdapter.java @@ -88,7 +88,9 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter { + repoStargazers.setOnClickListener(stargazers -> { Intent intent = new Intent(context, RepoStargazersActivity.class); intent.putExtra("repoFullNameForStars", fullName.getText()); @@ -111,7 +113,7 @@ public class StarredReposListAdapter extends RecyclerView.Adapter { + repoWatchers.setOnClickListener(watchers -> { Intent intentW = new Intent(context, RepoWatchersActivity.class); intentW.putExtra("repoFullNameForWatchers", fullName.getText()); diff --git a/app/src/main/res/layout/bottom_sheet_issue_comments.xml b/app/src/main/res/layout/bottom_sheet_issue_comments.xml new file mode 100644 index 00000000..8f978a16 --- /dev/null +++ b/app/src/main/res/layout/bottom_sheet_issue_comments.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet_labels_in_list.xml b/app/src/main/res/layout/bottom_sheet_labels_in_list.xml new file mode 100644 index 00000000..9527ffad --- /dev/null +++ b/app/src/main/res/layout/bottom_sheet_labels_in_list.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/bottom_sheet_repository_in_list.xml b/app/src/main/res/layout/bottom_sheet_repository_in_list.xml index e370244e..be1c0d65 100644 --- a/app/src/main/res/layout/bottom_sheet_repository_in_list.xml +++ b/app/src/main/res/layout/bottom_sheet_repository_in_list.xml @@ -17,6 +17,18 @@ android:orientation="vertical" android:layout_height="wrap_content"> + + - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/menu/labels_menu.xml b/app/src/main/res/menu/labels_menu.xml deleted file mode 100644 index 402bae55..00000000 --- a/app/src/main/res/menu/labels_menu.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - \ No newline at end of file From 9988649714f0fcc4d2694f4657722143fa31835a Mon Sep 17 00:00:00 2001 From: M M Arif Date: Wed, 1 Apr 2020 14:51:37 +0500 Subject: [PATCH 3/4] cleanup --- .../gitnex/adapters/IssueCommentsAdapter.java | 55 ------------------- 1 file changed, 55 deletions(-) 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 45a8fc80..dc2e8403 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java @@ -115,61 +115,6 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter Date: Thu, 2 Apr 2020 01:16:07 +0200 Subject: [PATCH 4/4] remove pointless if statements --- .../java/org/mian/gitnex/adapters/IssueCommentsAdapter.java | 6 +----- .../main/java/org/mian/gitnex/adapters/IssuesAdapter.java | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) 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 3514aeb3..0400dc93 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/IssueCommentsAdapter.java @@ -177,11 +177,7 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter issueAssigneeAvatar.setOnClickListener(new ClickListener(context.getResources().getString(R.string.issueCreator) + issuesModel.getUser().getLogin(), context)); } - if (issuesModel.getUser().getAvatar_url() != null) { - Picasso.get().load(issuesModel.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(issueAssigneeAvatar); - } else { - Picasso.get().load(issuesModel.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(issueAssigneeAvatar); - } + Picasso.get().load(issuesModel.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(issueAssigneeAvatar); String issueNumber_ = "" + context.getResources().getString(R.string.hash) + issuesModel.getNumber() + ""; issueTitle.setText(Html.fromHtml(issueNumber_ + " " + issuesModel.getTitle()));