2019-09-14 08:29:20 +02:00
|
|
|
package org.mian.gitnex.activities;
|
|
|
|
|
|
|
|
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.lifecycle.ViewModelProvider;
|
2019-09-14 08:29:20 +02:00
|
|
|
import org.mian.gitnex.R;
|
2021-12-15 20:20:49 +01:00
|
|
|
import org.mian.gitnex.adapters.UserGridAdapter;
|
2021-01-26 16:10:31 +01:00
|
|
|
import org.mian.gitnex.databinding.ActivityRepoWatchersBinding;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
2019-09-14 08:29:20 +02:00
|
|
|
import org.mian.gitnex.viewmodels.RepoWatchersViewModel;
|
|
|
|
|
|
|
|
/**
|
2022-07-29 14:08:44 +02:00
|
|
|
* @author M M Arif
|
2019-09-14 08:29:20 +02:00
|
|
|
*/
|
2020-03-04 15:54:21 +01:00
|
|
|
public class RepoWatchersActivity extends BaseActivity {
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private TextView noDataWatchers;
|
|
|
|
private View.OnClickListener onClickListener;
|
|
|
|
private UserGridAdapter adapter;
|
|
|
|
private GridView mGridView;
|
|
|
|
private ProgressBar mProgressBar;
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private RepositoryContext repository;
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
@Override
|
|
|
|
public void onCreate(Bundle savedInstanceState) {
|
2020-04-28 15:47:25 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
super.onCreate(savedInstanceState);
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
ActivityRepoWatchersBinding activityRepoWatchersBinding =
|
|
|
|
ActivityRepoWatchersBinding.inflate(getLayoutInflater());
|
2022-08-15 16:26:02 +02:00
|
|
|
setContentView(activityRepoWatchersBinding.getRoot());
|
2021-01-26 16:10:31 +01:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
ImageView closeActivity = activityRepoWatchersBinding.close;
|
|
|
|
TextView toolbarTitle = activityRepoWatchersBinding.toolbarTitle;
|
|
|
|
noDataWatchers = activityRepoWatchersBinding.noDataWatchers;
|
|
|
|
mGridView = activityRepoWatchersBinding.gridView;
|
|
|
|
mProgressBar = activityRepoWatchersBinding.progressBar;
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
repository = RepositoryContext.fromIntent(getIntent());
|
|
|
|
final String repoOwner = repository.getOwner();
|
|
|
|
final String repoName = repository.getName();
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
initCloseListener();
|
|
|
|
closeActivity.setOnClickListener(onClickListener);
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
toolbarTitle.setText(R.string.repoWatchersInMenu);
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
fetchDataAsync(repoOwner, repoName);
|
|
|
|
}
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void fetchDataAsync(String repoOwner, String repoName) {
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
RepoWatchersViewModel repoWatchersModel =
|
|
|
|
new ViewModelProvider(this).get(RepoWatchersViewModel.class);
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
repoWatchersModel
|
|
|
|
.getRepoWatchers(repoOwner, repoName, ctx)
|
|
|
|
.observe(
|
|
|
|
this,
|
|
|
|
watchersListMain -> {
|
|
|
|
adapter = new UserGridAdapter(ctx, watchersListMain);
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
if (adapter.getCount() > 0) {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
mGridView.setAdapter(adapter);
|
|
|
|
noDataWatchers.setVisibility(View.GONE);
|
|
|
|
} else {
|
2020-10-29 14:13:19 +01:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
adapter.notifyDataSetChanged();
|
|
|
|
mGridView.setAdapter(adapter);
|
|
|
|
noDataWatchers.setVisibility(View.VISIBLE);
|
|
|
|
}
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-09-21 07:43:00 +02:00
|
|
|
mProgressBar.setVisibility(View.GONE);
|
|
|
|
});
|
2022-08-15 16:26:02 +02:00
|
|
|
}
|
2019-09-14 08:29:20 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
private void initCloseListener() {
|
2020-08-06 17:16:51 +02:00
|
|
|
|
2022-08-15 16:26:02 +02:00
|
|
|
onClickListener = view -> finish();
|
|
|
|
}
|
2019-09-14 08:29:20 +02:00
|
|
|
|
Don't use TinyDB as cache (#1034)
Do not use TinyDB as a cache or a way to send data between activities.
### How is this working
Instead of saving everything into the TinyDB, I created three `Context`s (a `RepositoryContext`, an `IssueContext` and an `AccountContext`). All are used to store things like API or database values/models and additional data, e.g. the `RepositoryContext` also contains information about the current filter state of a repository (issues, pull requests, releases/tags and milestones). These are sent using `Intent`s and `Bundle`s between activities and fragments. Changing a field (e.g. filter state) in any fragment changes it also for the whole repository (or at least it should do so).
Due to the size of the changes (after https://codeberg.org/gitnex/GitNex/commit/c9172f85efafd9f25739fdd8385e1904b711ea41, Git says `154 files changed, 3318 insertions(+), 3835 deletions(-)`) **I highly recommend you to create a beta/pre release before releasing a stable version**.
Additional changes:
* after logging out, the account remains in the account list (with a note) and you can log in again (you can't switch to this account)
* repositories and organizations are clickable on user profiles
* deleted two unused classes
Once finished, hopefully
* closes #354
* replaces #897
* fixes #947
* closes #1001
* closes #1015
* marks #876 and #578 as `Wontfix` since they are not necessary at this point
* and all the other TinyDB issues
Co-authored-by: qwerty287 <ndev@web.de>
Co-authored-by: M M Arif <mmarif@noreply.codeberg.org>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/1034
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: qwerty287 <qwerty287@noreply.codeberg.org>
Co-committed-by: qwerty287 <qwerty287@noreply.codeberg.org>
2022-03-13 03:59:13 +01:00
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
repository.checkAccountSwitch(this);
|
|
|
|
}
|
2019-09-14 08:29:20 +02:00
|
|
|
}
|