Share feature and some refactor to easily manage source code files

This commit is contained in:
M M Arif
2020-03-17 00:28:03 +05:00
parent c2e80199ca
commit 79bd96f6a2
28 changed files with 134 additions and 57 deletions

View File

@@ -21,7 +21,7 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.AdminGetUsersAdapter;
import org.mian.gitnex.fragments.AdminUsersBottomSheetFragment;
import org.mian.gitnex.fragments.BottomSheetAdminUsersFragment;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.AppUtil;
@@ -34,7 +34,7 @@ import java.util.Objects;
* Author M M Arif
*/
public class AdminGetUsersActivity extends BaseActivity implements AdminUsersBottomSheetFragment.BottomSheetListener {
public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAdminUsersFragment.BottomSheetListener {
private View.OnClickListener onClickListener;
final Context ctx = this;
@@ -171,7 +171,7 @@ public class AdminGetUsersActivity extends BaseActivity implements AdminUsersBot
finish();
return true;
case R.id.genericMenu:
AdminUsersBottomSheetFragment bottomSheet = new AdminUsersBottomSheetFragment();
BottomSheetAdminUsersFragment bottomSheet = new BottomSheetAdminUsersFragment();
bottomSheet.show(getSupportFragmentManager(), "usersBottomSheet");
return true;
default:

View File

@@ -4,7 +4,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -55,7 +55,7 @@ import com.vdurmont.emoji.EmojiParser;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.IssueCommentsAdapter;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.fragments.SingleIssueBottomSheetFragment;
import org.mian.gitnex.fragments.BottomSheetSingleIssueFragment;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TimeHelper;
@@ -211,7 +211,7 @@ public class IssueDetailActivity extends BaseActivity {
finish();
return true;
case R.id.genericMenu:
SingleIssueBottomSheetFragment bottomSheet = new SingleIssueBottomSheetFragment();
BottomSheetSingleIssueFragment bottomSheet = new BottomSheetSingleIssueFragment();
bottomSheet.show(getSupportFragmentManager(), "singleIssueBottomSheet");
return true;
default:
@@ -293,7 +293,7 @@ public class IssueDetailActivity extends BaseActivity {
private void fetchDataAsync(String instanceUrl, String instanceToken, String owner, String repo, int index, String loginUid) {
IssueCommentsViewModel issueCommentsModel = ViewModelProviders.of(this).get(IssueCommentsViewModel.class);
IssueCommentsViewModel issueCommentsModel = new ViewModelProvider(this).get(IssueCommentsViewModel.class);
issueCommentsModel.getIssueCommentList(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), owner, repo, index, getApplicationContext()).observe(this, new Observer<List<IssueComments>>() {
@Override

View File

@@ -26,7 +26,7 @@ import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.fragments.AboutFragment;
import org.mian.gitnex.fragments.ExploreRepositoriesFragment;
import org.mian.gitnex.fragments.MyRepositoriesFragment;
import org.mian.gitnex.fragments.NavSubMenuBottomSheetFragment;
import org.mian.gitnex.fragments.BottomSheetNavSubMenuFragment;
import org.mian.gitnex.fragments.OrganizationsFragment;
import org.mian.gitnex.fragments.SettingsFragment;
import org.mian.gitnex.fragments.StarredRepositoriesFragment;
@@ -161,7 +161,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
ImageView navSubMenu = hView.findViewById(R.id.navSubMenu);
navSubMenu.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
NavSubMenuBottomSheetFragment bottomSheet = new NavSubMenuBottomSheetFragment();
BottomSheetNavSubMenuFragment bottomSheet = new BottomSheetNavSubMenuFragment();
bottomSheet.show(getSupportFragmentManager(), "adminMenuBottomSheet");
}
});

View File

@@ -18,7 +18,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.fragments.MembersByOrgFragment;
import org.mian.gitnex.fragments.OrgBottomSheetFragment;
import org.mian.gitnex.fragments.BottomSheetOrganizationFragment;
import org.mian.gitnex.fragments.OrganizationInfoFragment;
import org.mian.gitnex.fragments.RepositoriesByOrgFragment;
import org.mian.gitnex.fragments.TeamsByOrgFragment;
@@ -29,7 +29,7 @@ import java.util.Objects;
* Author M M Arif
*/
public class OrgDetailActivity extends BaseActivity implements OrgBottomSheetFragment.BottomSheetListener {
public class OrgDetailActivity extends BaseActivity implements BottomSheetOrganizationFragment.BottomSheetListener {
@Override
protected int getLayoutResourceId(){
@@ -118,7 +118,7 @@ public class OrgDetailActivity extends BaseActivity implements OrgBottomSheetFra
finish();
return true;
case R.id.repoMenu:
OrgBottomSheetFragment bottomSheet = new OrgBottomSheetFragment();
BottomSheetOrganizationFragment bottomSheet = new BottomSheetOrganizationFragment();
bottomSheet.show(getSupportFragmentManager(), "orgBottomSheet");
return true;
default:

View File

@@ -25,6 +25,7 @@ import android.view.ViewGroup;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.fragments.BottomSheetRepoFragment;
import org.mian.gitnex.fragments.BranchesFragment;
import org.mian.gitnex.fragments.ClosedIssuesFragment;
import org.mian.gitnex.fragments.CollaboratorsFragment;
@@ -34,7 +35,6 @@ import org.mian.gitnex.fragments.LabelsFragment;
import org.mian.gitnex.fragments.MilestonesFragment;
import org.mian.gitnex.fragments.PullRequestsFragment;
import org.mian.gitnex.fragments.ReleasesFragment;
import org.mian.gitnex.fragments.RepoBottomSheetFragment;
import org.mian.gitnex.fragments.RepoInfoFragment;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.models.UserRepositories;
@@ -48,7 +48,7 @@ import android.net.Uri;
* Author M M Arif
*/
public class RepoDetailActivity extends BaseActivity implements RepoBottomSheetFragment.BottomSheetListener {
public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoFragment.BottomSheetListener {
private TextView textViewBadge;
@@ -185,7 +185,7 @@ public class RepoDetailActivity extends BaseActivity implements RepoBottomSheetF
finish();
return true;
case R.id.repoMenu:
RepoBottomSheetFragment bottomSheet = new RepoBottomSheetFragment();
BottomSheetRepoFragment bottomSheet = new BottomSheetRepoFragment();
bottomSheet.show(getSupportFragmentManager(), "repoBottomSheet");
return true;
default:
@@ -197,6 +197,14 @@ public class RepoDetailActivity extends BaseActivity implements RepoBottomSheetF
@Override
public void onButtonClicked(String text) {
TinyDB tinyDb = new TinyDB(getApplicationContext());
String repoFullName = tinyDb.getString("repoFullName");
String instanceUrlWithProtocol = "https://" + tinyDb.getString("instanceUrlRaw");
if(!tinyDb.getString("instanceUrlWithProtocol").isEmpty()) {
instanceUrlWithProtocol = tinyDb.getString("instanceUrlWithProtocol");
}
Uri url = Uri.parse(instanceUrlWithProtocol + "/" + repoFullName);
switch (text) {
case "label":
startActivity(new Intent(RepoDetailActivity.this, CreateLabelActivity.class));
@@ -214,16 +222,16 @@ public class RepoDetailActivity extends BaseActivity implements RepoBottomSheetF
startActivity(new Intent(RepoDetailActivity.this, CreateReleaseActivity.class));
break;
case "openWebRepo":
TinyDB tinyDb = new TinyDB(getApplicationContext());
String repoFullName = tinyDb.getString("repoFullName");
String instanceUrlWithProtocol = "https://" + tinyDb.getString("instanceUrlRaw");
if(!tinyDb.getString("instanceUrlWithProtocol").isEmpty()) {
instanceUrlWithProtocol = tinyDb.getString("instanceUrlWithProtocol");
}
Uri url = Uri.parse(instanceUrlWithProtocol + "/" + repoFullName);
Intent i = new Intent(Intent.ACTION_VIEW, url);
startActivity(i);
break;
case "shareRepo":
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, url);
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, url);
startActivity(Intent.createChooser(sharingIntent, url.toString()));
break;
case "newFile":
startActivity(new Intent(RepoDetailActivity.this, NewFileActivity.class));
break;

View File

@@ -58,7 +58,7 @@ public class ClosedIssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
LayoutInflater inflater = LayoutInflater.from(context);
if(viewType == TYPE_LOAD){
return new ClosedIssuesAdapter.IssuesHolder(inflater.inflate(R.layout.repo_detail_issues_list, parent,false));
return new ClosedIssuesAdapter.IssuesHolder(inflater.inflate(R.layout.repo_issues_list, parent,false));
}
else {
return new ClosedIssuesAdapter.LoadHolder(inflater.inflate(R.layout.row_load,parent,false));

View File

@@ -58,7 +58,7 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
LayoutInflater inflater = LayoutInflater.from(context);
if(viewType == TYPE_LOAD){
return new IssuesHolder(inflater.inflate(R.layout.repo_detail_issues_list, parent,false));
return new IssuesHolder(inflater.inflate(R.layout.repo_issues_list, parent,false));
}
else {
return new LoadHolder(inflater.inflate(R.layout.row_load,parent,false));

View File

@@ -15,14 +15,14 @@ import org.mian.gitnex.R;
* Author M M Arif
*/
public class AdminUsersBottomSheetFragment extends BottomSheetDialogFragment {
public class BottomSheetAdminUsersFragment extends BottomSheetDialogFragment {
private AdminUsersBottomSheetFragment.BottomSheetListener bmListener;
private BottomSheetAdminUsersFragment.BottomSheetListener bmListener;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.admin_users_bottom_sheet_layout, container, false);
View v = inflater.inflate(R.layout.bottom_sheet_admin_users_layout, container, false);
TextView createNewUser = v.findViewById(R.id.createNewUser);
@@ -46,7 +46,7 @@ public class AdminUsersBottomSheetFragment extends BottomSheetDialogFragment {
super.onAttach(context);
try {
bmListener = (AdminUsersBottomSheetFragment.BottomSheetListener) context;
bmListener = (BottomSheetAdminUsersFragment.BottomSheetListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
+ " must implement BottomSheetListener");

View File

@@ -16,12 +16,12 @@ import androidx.annotation.Nullable;
* Author M M Arif
*/
public class NavSubMenuBottomSheetFragment extends BottomSheetDialogFragment {
public class BottomSheetNavSubMenuFragment extends BottomSheetDialogFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.nav_sub_menu_bottom_sheet_layout, container, false);
View v = inflater.inflate(R.layout.bottom_sheet_nav_sub_menu_layout, container, false);
TextView adminUsers = v.findViewById(R.id.adminUsers);

View File

@@ -15,14 +15,14 @@ import androidx.annotation.Nullable;
* Author M M Arif
*/
public class OrgBottomSheetFragment extends BottomSheetDialogFragment {
public class BottomSheetOrganizationFragment extends BottomSheetDialogFragment {
private OrgBottomSheetFragment.BottomSheetListener bmListener;
private BottomSheetOrganizationFragment.BottomSheetListener bmListener;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.org_bottom_sheet_layout, container, false);
View v = inflater.inflate(R.layout.bottom_sheet_organization_layout, container, false);
TextView createTeam = v.findViewById(R.id.createTeam);
@@ -46,7 +46,7 @@ public class OrgBottomSheetFragment extends BottomSheetDialogFragment {
super.onAttach(context);
try {
bmListener = (OrgBottomSheetFragment.BottomSheetListener) context;
bmListener = (BottomSheetOrganizationFragment.BottomSheetListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
+ " must implement BottomSheetListener");

View File

@@ -16,12 +16,12 @@ import androidx.annotation.Nullable;
* Author M M Arif
*/
public class ProfileBottomSheetFragment extends BottomSheetDialogFragment {
public class BottomSheetProfileFragment extends BottomSheetDialogFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.profile_bottom_sheet_layout, container, false);
View v = inflater.inflate(R.layout.bottom_sheet_profile_layout, container, false);
TextView addNewEmailAddress = v.findViewById(R.id.addNewEmailAddress);

View File

@@ -17,14 +17,14 @@ import androidx.annotation.Nullable;
* Author M M Arif
*/
public class RepoBottomSheetFragment extends BottomSheetDialogFragment {
public class BottomSheetRepoFragment extends BottomSheetDialogFragment {
private BottomSheetListener bmListener;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.repo_bottom_sheet_layout, container, false);
View v = inflater.inflate(R.layout.bottom_sheet_repo_layout, container, false);
final TinyDB tinyDb = new TinyDB(getContext());
@@ -39,6 +39,7 @@ public class RepoBottomSheetFragment extends BottomSheetDialogFragment {
TextView unStarRepository = v.findViewById(R.id.unStarRepository);
TextView watchRepository = v.findViewById(R.id.watchRepository);
TextView unWatchRepository = v.findViewById(R.id.unWatchRepository);
TextView shareRepository = v.findViewById(R.id.shareRepository);
createLabel.setOnClickListener(new View.OnClickListener() {
@Override
@@ -86,6 +87,14 @@ public class RepoBottomSheetFragment extends BottomSheetDialogFragment {
}
});
shareRepository.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bmListener.onButtonClicked("shareRepo");
dismiss();
}
});
openWebRepo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

View File

@@ -27,13 +27,13 @@ import java.util.Objects;
* Author M M Arif
*/
public class SingleIssueBottomSheetFragment extends BottomSheetDialogFragment {
public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.single_issue_bottom_sheet_layout, container, false);
View v = inflater.inflate(R.layout.bottom_sheet_single_issue_layout, container, false);
final TinyDB tinyDB = new TinyDB(getContext());
@@ -46,6 +46,7 @@ public class SingleIssueBottomSheetFragment extends BottomSheetDialogFragment {
TextView copyIssueUrl = v.findViewById(R.id.copyIssueUrl);
TextView openFilesDiff = v.findViewById(R.id.openFilesDiff);
TextView mergePullRequest = v.findViewById(R.id.mergePullRequest);
TextView shareIssue = v.findViewById(R.id.shareIssue);
replyToIssue.setOnClickListener(new View.OnClickListener() {
@Override
@@ -133,6 +134,29 @@ public class SingleIssueBottomSheetFragment extends BottomSheetDialogFragment {
}
});
shareIssue.setOnClickListener(v1 -> {
// get url of repo
String repoFullName = tinyDB.getString("repoFullName");
String instanceUrlWithProtocol = "https://" + tinyDB.getString("instanceUrlRaw");
if (!tinyDB.getString("instanceUrlWithProtocol").isEmpty()) {
instanceUrlWithProtocol = tinyDB.getString("instanceUrlWithProtocol");
}
// get issue Url
String issueUrl = instanceUrlWithProtocol + "/" + repoFullName + "/issues/" + tinyDB.getString("issueNumber");
// share issue
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getResources().getString(R.string.hash) + tinyDB.getString("issueNumber") + " " + tinyDB.getString("issueTitle"));
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, issueUrl);
startActivity(Intent.createChooser(sharingIntent, getResources().getString(R.string.hash) + tinyDB.getString("issueNumber") + " " + tinyDB.getString("issueTitle")));
dismiss();
});
copyIssueUrl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@@ -170,7 +194,7 @@ public class SingleIssueBottomSheetFragment extends BottomSheetDialogFragment {
@Override
public void onClick(View v) {
IssueActions.closeReopenIssue(getContext(), Integer.valueOf(tinyDB.getString("issueNumber")), "closed");
IssueActions.closeReopenIssue(getContext(), Integer.parseInt(tinyDB.getString("issueNumber")), "closed");
dismiss();
}
@@ -184,7 +208,7 @@ public class SingleIssueBottomSheetFragment extends BottomSheetDialogFragment {
@Override
public void onClick(View v) {
IssueActions.closeReopenIssue(getContext(), Integer.valueOf(tinyDB.getString("issueNumber")), "open");
IssueActions.closeReopenIssue(getContext(), Integer.parseInt(tinyDB.getString("issueNumber")), "open");
dismiss();
}

View File

@@ -52,7 +52,7 @@ public class ProfileFragment extends Fragment {
userLogin.setText(getString(R.string.usernameWithAt, tinyDb.getString("userLogin")));
userEmail.setText(tinyDb.getString("userEmail"));
ProfileFragment.SectionsPagerAdapter mSectionsPagerAdapter = new ProfileFragment.SectionsPagerAdapter(getFragmentManager());
ProfileFragment.SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
ViewPager mViewPager = v.findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
@@ -101,7 +101,7 @@ public class ProfileFragment extends Fragment {
}
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
public static class SectionsPagerAdapter extends FragmentStatePagerAdapter {
SectionsPagerAdapter(FragmentManager fm) {
super(fm);
@@ -147,9 +147,8 @@ public class ProfileFragment extends Fragment {
((MainActivity)ctx).finish();
return true;
case R.id.profileMenu:
ProfileBottomSheetFragment bottomSheet = new ProfileBottomSheetFragment();
assert getFragmentManager() != null;
bottomSheet.show(getFragmentManager(), "profileBottomSheet");
BottomSheetProfileFragment bottomSheet = new BottomSheetProfileFragment();
bottomSheet.show(getChildFragmentManager(), "profileBottomSheet");
return true;
default:
return super.onOptionsItemSelected(item);