2019-09-14 08:29:20 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
import android.content.Context;
|
2019-09-14 08:29:20 +02:00
|
|
|
import android.os.Bundle;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.GridView;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.ProgressBar;
|
|
|
|
import android.widget.TextView;
|
2020-07-07 19:15:01 +02:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.lifecycle.Observer;
|
|
|
|
import androidx.lifecycle.ViewModelProvider;
|
2019-09-14 08:29:20 +02:00
|
|
|
import org.mian.gitnex.R;
|
|
|
|
import org.mian.gitnex.adapters.RepoWatchersAdapter;
|
|
|
|
import org.mian.gitnex.helpers.Authorization;
|
2020-07-07 19:15:01 +02:00
|
|
|
import org.mian.gitnex.helpers.TinyDB;
|
2019-09-14 08:29:20 +02:00
|
|
|
import org.mian.gitnex.models.UserInfo;
|
|
|
|
import org.mian.gitnex.viewmodels.RepoWatchersViewModel;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Author M M Arif
|
|
|
|
*/
|
|
|
|
|
2020-03-04 15:54:21 +01:00
|
|
|
public class RepoWatchersActivity extends BaseActivity {
|
2019-09-14 08:29:20 +02:00
|
|
|
|
|
|
|
private TextView noDataWatchers;
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private RepoWatchersAdapter adapter;
|
|
|
|
private GridView mGridView;
|
|
|
|
private ProgressBar mProgressBar;
|
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
final Context ctx = this;
|
|
|
|
private Context appCtx;
|
|
|
|
|
2019-09-14 08:29:20 +02:00
|
|
|
@Override
|
2020-03-04 15:54:21 +01:00
|
|
|
protected int getLayoutResourceId(){
|
|
|
|
return R.layout.activity_repo_watchers;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2020-04-28 15:47:25 +02:00
|
|
|
|
2019-09-14 08:29:20 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2020-04-28 15:47:25 +02:00
|
|
|
appCtx = getApplicationContext();
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
TinyDB tinyDb = new TinyDB(appCtx);
|
2019-09-14 08:29:20 +02:00
|
|
|
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);
|
|
|
|
noDataWatchers = findViewById(R.id.noDataWatchers);
|
|
|
|
mGridView = findViewById(R.id.gridView);
|
|
|
|
mProgressBar = findViewById(R.id.progress_bar);
|
|
|
|
|
|
|
|
String repoFullNameForWatchers = getIntent().getStringExtra("repoFullNameForWatchers");
|
|
|
|
String[] parts = repoFullNameForWatchers.split("/");
|
|
|
|
final String repoOwner = parts[0];
|
|
|
|
final String repoName = parts[1];
|
|
|
|
|
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
|
|
|
|
|
|
|
toolbarTitle.setText(R.string.repoWatchersInMenu);
|
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
2019-09-14 08:29:20 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void fetchDataAsync(String instanceUrl, String instanceToken, String repoOwner, String repoName) {
|
|
|
|
|
|
|
|
RepoWatchersViewModel repoWatchersModel = new ViewModelProvider(this).get(RepoWatchersViewModel.class);
|
|
|
|
|
2020-04-28 15:47:25 +02:00
|
|
|
repoWatchersModel.getRepoWatchers(instanceUrl, instanceToken, repoOwner, repoName, ctx).observe(this, new Observer<List<UserInfo>>() {
|
2019-09-14 08:29:20 +02:00
|
|
|
@Override
|
|
|
|
public void onChanged(@Nullable List<UserInfo> watchersListMain) {
|
2020-04-28 15:47:25 +02:00
|
|
|
adapter = new RepoWatchersAdapter(ctx, watchersListMain);
|
2019-09-14 08:29:20 +02:00
|
|
|
if(adapter.getCount() > 0) {
|
|
|
|
mGridView.setAdapter(adapter);
|
|
|
|
noDataWatchers.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
mGridView.setAdapter(adapter);
|
|
|
|
noDataWatchers.setVisibility(View.VISIBLE);
|
|
|
|
}
|
|
|
|
mProgressBar.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void initCloseListener() {
|
2020-08-06 17:16:51 +02:00
|
|
|
|
|
|
|
onClickListener = view -> finish();
|
2019-09-14 08:29:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|