diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index ea556b0b..387fd362 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,8 +2,8 @@ - + - + + diff --git a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java index 8dfba64f..05afde24 100644 --- a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java @@ -330,6 +330,9 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On if (response.code() == 200) { assert userDetails != null; + if(userDetails.getIs_admin() != null) { + tinyDb.putBoolean("userIsAdmin", userDetails.getIs_admin()); + } tinyDb.putString("userLogin", userDetails.getLogin()); tinyDb.putInt("userId", userDetails.getId()); if(!userDetails.getFullname().equals("")) { diff --git a/app/src/main/java/org/mian/gitnex/activities/OrgTeamMembersActivity.java b/app/src/main/java/org/mian/gitnex/activities/OrgTeamMembersActivity.java index a55d65ff..07f1118c 100644 --- a/app/src/main/java/org/mian/gitnex/activities/OrgTeamMembersActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/OrgTeamMembersActivity.java @@ -3,9 +3,8 @@ package org.mian.gitnex.activities; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.lifecycle.Observer; -import androidx.lifecycle.ViewModelProviders; +import androidx.lifecycle.ViewModelProvider; import android.os.Bundle; -import android.util.Log; import android.view.View; import android.widget.GridView; import android.widget.ImageView; @@ -63,7 +62,7 @@ public class OrgTeamMembersActivity extends AppCompatActivity { } getIntent().getStringExtra("teamId"); - Log.i("teamId", getIntent().getStringExtra("teamId")); + //Log.i("teamId", getIntent().getStringExtra("teamId")); fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), Integer.valueOf(teamId)); @@ -71,7 +70,7 @@ public class OrgTeamMembersActivity extends AppCompatActivity { private void fetchDataAsync(String instanceUrl, String instanceToken, int teamId) { - TeamMembersByOrgViewModel teamMembersModel = ViewModelProviders.of(this).get(TeamMembersByOrgViewModel.class); + TeamMembersByOrgViewModel teamMembersModel = new ViewModelProvider(this).get(TeamMembersByOrgViewModel.class); teamMembersModel.getMembersByOrgList(instanceUrl, instanceToken, teamId).observe(this, new Observer>() { @Override diff --git a/app/src/main/java/org/mian/gitnex/activities/RepoStargazersActivity.java b/app/src/main/java/org/mian/gitnex/activities/RepoStargazersActivity.java new file mode 100644 index 00000000..8fbbfc6a --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/activities/RepoStargazersActivity.java @@ -0,0 +1,96 @@ +package org.mian.gitnex.activities; + +import android.content.Context; +import android.os.Bundle; +import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; +import androidx.lifecycle.Observer; +import androidx.lifecycle.ViewModelProvider; +import android.view.View; +import android.widget.GridView; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.TextView; +import org.mian.gitnex.R; +import org.mian.gitnex.adapters.RepoStargazersAdapter; +import org.mian.gitnex.helpers.Authorization; +import org.mian.gitnex.models.UserInfo; +import org.mian.gitnex.util.TinyDB; +import org.mian.gitnex.viewmodels.RepoStargazersViewModel; +import java.util.List; + +/** + * Author M M Arif + */ + +public class RepoStargazersActivity extends AppCompatActivity { + + private TextView noDataStargazers; + private View.OnClickListener onClickListener; + private RepoStargazersAdapter adapter; + private GridView mGridView; + private ProgressBar mProgressBar; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_repo_stargazers); + + TinyDB tinyDb = new TinyDB(getApplicationContext()); + final String instanceUrl = tinyDb.getString("instanceUrl"); + final String loginUid = tinyDb.getString("loginUid"); + final String instanceToken = "token " + tinyDb.getString(loginUid + "-token"); + + ImageView closeActivity = findViewById(R.id.close); + TextView toolbarTitle = findViewById(R.id.toolbar_title); + noDataStargazers = findViewById(R.id.noDataStargazers); + mGridView = findViewById(R.id.gridView); + mProgressBar = findViewById(R.id.progress_bar); + + String repoFullNameForStars = getIntent().getStringExtra("repoFullNameForStars"); + String[] parts = repoFullNameForStars.split("/"); + final String repoOwner = parts[0]; + final String repoName = parts[1]; + + initCloseListener(); + closeActivity.setOnClickListener(onClickListener); + + toolbarTitle.setText(R.string.repoStargazersInMenu); + + fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getApplicationContext(), loginUid, instanceToken), repoOwner, repoName); + + } + + private void fetchDataAsync(String instanceUrl, String instanceToken, String repoOwner, String repoName) { + + RepoStargazersViewModel repoStargazersModel = new ViewModelProvider(this).get(RepoStargazersViewModel.class); + + repoStargazersModel.getRepoStargazers(instanceUrl, instanceToken, repoOwner, repoName).observe(this, new Observer>() { + @Override + public void onChanged(@Nullable List stargazersListMain) { + adapter = new RepoStargazersAdapter(getApplicationContext(), stargazersListMain); + if(adapter.getCount() > 0) { + mGridView.setAdapter(adapter); + noDataStargazers.setVisibility(View.GONE); + } + else { + adapter.notifyDataSetChanged(); + mGridView.setAdapter(adapter); + noDataStargazers.setVisibility(View.VISIBLE); + } + mProgressBar.setVisibility(View.GONE); + } + }); + + } + + private void initCloseListener() { + onClickListener = new View.OnClickListener() { + @Override + public void onClick(View view) { + finish(); + } + }; + } + +} 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 9325fe40..cb1967ee 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java @@ -4,6 +4,7 @@ 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; @@ -14,11 +15,15 @@ import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; import org.mian.gitnex.R; import org.mian.gitnex.activities.RepoDetailActivity; +import org.mian.gitnex.activities.RepoStargazersActivity; 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; /** @@ -52,6 +57,7 @@ public class MyReposListAdapter extends RecyclerView.Adapter stargazersList; + private Context mCtx; + + private class ViewHolder { + + private ImageView memberAvatar; + private TextView memberName; + + ViewHolder(View v) { + memberAvatar = v.findViewById(R.id.memberAvatar); + memberName = v.findViewById(R.id.memberName); + } + } + + public RepoStargazersAdapter(Context mCtx, List membersListMain) { + this.mCtx = mCtx; + this.stargazersList = membersListMain; + } + + @Override + public int getCount() { + return stargazersList.size(); + } + + @Override + public Object getItem(int position) { + return null; + } + + @Override + public long getItemId(int position) { + return 0; + } + + @SuppressLint("InflateParams") + @Override + public View getView(int position, View finalView, ViewGroup parent) { + + RepoStargazersAdapter.ViewHolder viewHolder; + + if (finalView == null) { + finalView = LayoutInflater.from(mCtx).inflate(R.layout.repo_stargazers_list, null); + viewHolder = new RepoStargazersAdapter.ViewHolder(finalView); + finalView.setTag(viewHolder); + } + else { + viewHolder = (RepoStargazersAdapter.ViewHolder) finalView.getTag(); + } + + initData(viewHolder, position); + return finalView; + + } + + private void initData(RepoStargazersAdapter.ViewHolder viewHolder, int position) { + + UserInfo currentItem = stargazersList.get(position); + Picasso.get().load(currentItem.getAvatar()).transform(new RoundedTransformation(100, 0)).resize(200, 200).centerCrop().into(viewHolder.memberAvatar); + + if(!currentItem.getFullname().equals("")) { + viewHolder.memberName.setText(currentItem.getFullname()); + } + else { + viewHolder.memberName.setText(currentItem.getLogin()); + } + + } + +} 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 9c904d97..33bbf5d1 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/ReposListAdapter.java @@ -4,8 +4,11 @@ import android.content.Context; import android.content.Intent; import android.graphics.Typeface; import androidx.annotation.NonNull; +import androidx.appcompat.view.ContextThemeWrapper; +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,8 +19,10 @@ import com.amulyakhare.textdrawable.TextDrawable; import com.amulyakhare.textdrawable.util.ColorGenerator; import org.mian.gitnex.R; import org.mian.gitnex.activities.RepoDetailActivity; +import org.mian.gitnex.activities.RepoStargazersActivity; 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; @@ -43,6 +48,7 @@ public class ReposListAdapter extends RecyclerView.Adapter> adminGetUsers(@Header("Authorization") String token); + + @GET("repos/{owner}/{repo}/stargazers") // get all repo stars + Call> getRepoStargazers(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName); } \ No newline at end of file diff --git a/app/src/main/java/org/mian/gitnex/viewmodels/RepoStargazersViewModel.java b/app/src/main/java/org/mian/gitnex/viewmodels/RepoStargazersViewModel.java new file mode 100644 index 00000000..5cc13b2d --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/viewmodels/RepoStargazersViewModel.java @@ -0,0 +1,60 @@ +package org.mian.gitnex.viewmodels; + +import android.util.Log; +import androidx.annotation.NonNull; +import androidx.lifecycle.LiveData; +import androidx.lifecycle.MutableLiveData; +import androidx.lifecycle.ViewModel; +import org.mian.gitnex.clients.RetrofitClient; +import org.mian.gitnex.models.UserInfo; +import java.util.List; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; + +/** + * Author M M Arif + */ + +public class RepoStargazersViewModel extends ViewModel { + + private static MutableLiveData> stargazersList; + + public LiveData> getRepoStargazers(String instanceUrl, String token, String repoOwner, String repoName) { + + stargazersList = new MutableLiveData<>(); + loadRepoStargazers(instanceUrl, token, repoOwner, repoName); + + return stargazersList; + } + + public static void loadRepoStargazers(String instanceUrl, String token, String repoOwner, String repoName) { + + Call> call = RetrofitClient + .getInstance(instanceUrl) + .getApiInterface() + .getRepoStargazers(token, repoOwner, repoName); + + call.enqueue(new Callback>() { + + @Override + public void onResponse(@NonNull Call> call, @NonNull Response> response) { + + if(response.isSuccessful()) { + if(response.code() == 200) { + stargazersList.postValue(response.body()); + + } + } + + } + + @Override + public void onFailure(@NonNull Call> call, Throwable t) { + Log.i("onFailure", t.toString()); + } + + }); + + } +} diff --git a/app/src/main/res/layout/activity_repo_stargazers.xml b/app/src/main/res/layout/activity_repo_stargazers.xml new file mode 100644 index 00000000..e1b407eb --- /dev/null +++ b/app/src/main/res/layout/activity_repo_stargazers.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/my_repos_list.xml b/app/src/main/res/layout/my_repos_list.xml index afbce91e..3507b16c 100644 --- a/app/src/main/res/layout/my_repos_list.xml +++ b/app/src/main/res/layout/my_repos_list.xml @@ -85,13 +85,28 @@ android:layout_marginBottom="8dp" android:orientation="horizontal"> + + @@ -99,30 +114,25 @@ - - - + android:layout_gravity="end" + android:scaleType="fitEnd" + android:src="@drawable/ic_dotted_menu_horizontal" + android:contentDescription="@string/menuContentDesc" /> diff --git a/app/src/main/res/layout/repo_detail_issues_list.xml b/app/src/main/res/layout/repo_detail_issues_list.xml index 369443fd..f3646277 100644 --- a/app/src/main/res/layout/repo_detail_issues_list.xml +++ b/app/src/main/res/layout/repo_detail_issues_list.xml @@ -38,7 +38,7 @@ android:height="16dp" android:layout_marginEnd="15dp" android:layout_below="@+id/assigneeAvatar" - android:drawableTop="@drawable/ic_issue_comments" + android:drawableTop="@drawable/ic_comment" android:gravity="center" android:textColor="@color/colorWhite" android:textSize="14sp" /> diff --git a/app/src/main/res/layout/repo_stargazers_list.xml b/app/src/main/res/layout/repo_stargazers_list.xml new file mode 100644 index 00000000..b71a03fc --- /dev/null +++ b/app/src/main/res/layout/repo_stargazers_list.xml @@ -0,0 +1,27 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/repos_list.xml b/app/src/main/res/layout/repos_list.xml index 400953a0..7194eae2 100644 --- a/app/src/main/res/layout/repos_list.xml +++ b/app/src/main/res/layout/repos_list.xml @@ -85,13 +85,28 @@ android:layout_marginBottom="8dp" android:orientation="horizontal"> + + @@ -99,30 +114,25 @@ - - - + android:layout_gravity="end" + android:scaleType="fitEnd" + android:src="@drawable/ic_dotted_menu_horizontal" + android:contentDescription="@string/menuContentDesc" /> diff --git a/app/src/main/res/layout/repositories_by_org_list.xml b/app/src/main/res/layout/repositories_by_org_list.xml index 400953a0..7194eae2 100644 --- a/app/src/main/res/layout/repositories_by_org_list.xml +++ b/app/src/main/res/layout/repositories_by_org_list.xml @@ -85,13 +85,28 @@ android:layout_marginBottom="8dp" android:orientation="horizontal"> + + @@ -99,30 +114,25 @@ - - - + android:layout_gravity="end" + android:scaleType="fitEnd" + android:src="@drawable/ic_dotted_menu_horizontal" + android:contentDescription="@string/menuContentDesc" /> diff --git a/app/src/main/res/layout/starred_repos_list.xml b/app/src/main/res/layout/starred_repos_list.xml index 237813b0..5b3400fd 100644 --- a/app/src/main/res/layout/starred_repos_list.xml +++ b/app/src/main/res/layout/starred_repos_list.xml @@ -85,13 +85,28 @@ android:layout_marginBottom="8dp" android:orientation="horizontal"> + + @@ -99,30 +114,25 @@ - - - + android:layout_gravity="end" + android:scaleType="fitEnd" + android:src="@drawable/ic_dotted_menu_horizontal" + android:contentDescription="@string/menuContentDesc" /> diff --git a/app/src/main/res/menu/repo_dotted_list_menu.xml b/app/src/main/res/menu/repo_dotted_list_menu.xml new file mode 100644 index 00000000..6518de34 --- /dev/null +++ b/app/src/main/res/menu/repo_dotted_list_menu.xml @@ -0,0 +1,14 @@ + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index a6e5ce77..1ff6452e 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -397,6 +397,12 @@ OTP Code (Optional) Gebe den otp code ein wenn 2FA eingeschaltet ist + Stargazers + Watchers + No stars found + No watchers found + Star + OK Fertig diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index 5d5dbfa4..9a3e2c93 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -397,6 +397,12 @@ OTP Code (Optional) Enter the otp code if 2FA is enabled + Stargazers + Watchers + No stars found + No watchers found + Star + OK Done diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 4534a4f2..879caaa1 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -397,6 +397,12 @@ OTP Code (Optional) Enter the otp code if 2FA is enabled + Stargazers + Watchers + No stars found + No watchers found + Star + OK Готово diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7691dc75..5fbdf843 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -433,6 +433,12 @@ OTP Code (Optional) Enter the otp code if 2FA is enabled + Stargazers + Watchers + No stars found + No watchers found + Star + OK Done