Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message translation updates format improvements typo update some renaming refactors Use better naming convention remove duplicate source arrange draft titles enhance click listener area Launch drafts from reply screen and clean up Add message draft saved update repositories tasks Update user accounts repository with thread, remove async tasks remove async task in drafts update layout, change async to thread in drafts Merge branch 'master' into pull_139 # Conflicts: # app/build.gradle # app/src/main/java/org/mian/gitnex/activities/LoginActivity.java Merge branch 'master' into pull_139 # Conflicts: # app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139 # Conflicts: # app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java Merge branch 'master' into pull_139 # Conflicts: # app/src/main/java/org/mian/gitnex/activities/LoginActivity.java # app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java # app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java Merge branch 'master' into pull_139 Merge branch 'master' into pull_139 Merge branch 'master' into pull_139 and fix conflicts # Conflicts: # app/build.gradle # app/src/main/java/org/mian/gitnex/activities/LoginActivity.java # app/src/main/java/org/mian/gitnex/activities/MainActivity.java # app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java # app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java # app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java # app/src/main/res/values/strings.xml Code Format Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft # Conflicts: # app/src/main/java/org/mian/gitnex/activities/MainActivity.java # app/src/main/res/values/strings.xml Go to draft, save on type and other fixes delete all drafts, added messages where needed delete draft Force logout Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft # Conflicts: # app/src/main/java/org/mian/gitnex/activities/MainActivity.java # app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java check if account data is null, we need to log the user out for the 1st time. Merge branch 'master' into 15-comments-draft fix repo owner, name sequence Add comments for test, show drafts list Add repos to db Add account to db and other refactors to the code Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft Merge branch 'master' into 15-comments-draft # Conflicts: # app/build.gradle # app/src/main/AndroidManifest.xml Merge branch 'master' into 15-comments-draft merge more queries, added dao repositories, layout update Added queries in dao some refactor. added models, dao, entities (accounts, repositories, drafts) WIP on implementing drafts, introduced Room persistence library for db. Co-authored-by: M M Arif <mmarif@swatian.com> Co-authored-by: 6543 <6543@obermui.de> Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139 Reviewed-by: opyale <opyale@noreply.codeberg.org>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class BottomSheetDraftsFragment extends BottomSheetDialogFragment {
|
||||
|
||||
private String TAG = StaticGlobalVariables.tagDraftsBottomSheet;
|
||||
private BottomSheetDraftsFragment.BottomSheetListener bmListener;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.bottom_sheet_drafts, container, false);
|
||||
|
||||
TextView deleteAllDrafts = v.findViewById(R.id.deleteAllDrafts);
|
||||
|
||||
deleteAllDrafts.setOnClickListener(v1 -> {
|
||||
|
||||
dismiss();
|
||||
bmListener.onButtonClicked("deleteDrafts");
|
||||
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
public interface BottomSheetListener {
|
||||
void onButtonClicked(String text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
try {
|
||||
bmListener = (BottomSheetDraftsFragment.BottomSheetListener) context;
|
||||
}
|
||||
catch (ClassCastException e) {
|
||||
Log.e(TAG, e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
138
app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java
Normal file
138
app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java
Normal file
@@ -0,0 +1,138 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import android.os.Handler;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.adapters.DraftsAdapter;
|
||||
import org.mian.gitnex.database.models.DraftWithRepository;
|
||||
import org.mian.gitnex.database.api.DraftsApi;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class DraftsFragment extends Fragment {
|
||||
|
||||
private Context ctx;
|
||||
private DraftsAdapter adapter;
|
||||
private RecyclerView mRecyclerView;
|
||||
private DraftsApi draftsApi;
|
||||
private TextView noData;
|
||||
private List<DraftWithRepository> draftsList_;
|
||||
private int currentActiveAccountId;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_drafts, container, false);
|
||||
ctx = getContext();
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(ctx);
|
||||
|
||||
draftsList_ = new ArrayList<>();
|
||||
draftsApi = new DraftsApi(ctx);
|
||||
|
||||
noData = v.findViewById(R.id.noData);
|
||||
mRecyclerView = v.findViewById(R.id.recyclerView);
|
||||
final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);
|
||||
|
||||
mRecyclerView.setHasFixedSize(true);
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
|
||||
DividerItemDecoration.VERTICAL);
|
||||
mRecyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
adapter = new DraftsAdapter(getContext(), draftsList_);
|
||||
|
||||
swipeRefresh.setOnRefreshListener(() -> new Handler().postDelayed(() -> {
|
||||
|
||||
draftsList_.clear();
|
||||
swipeRefresh.setRefreshing(false);
|
||||
fetchDataAsync(1);
|
||||
|
||||
}, 250));
|
||||
|
||||
currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||
|
||||
fetchDataAsync(currentActiveAccountId);
|
||||
|
||||
return v;
|
||||
|
||||
}
|
||||
|
||||
private void fetchDataAsync(int accountId) {
|
||||
|
||||
draftsApi.getDrafts(accountId).observe(getViewLifecycleOwner(), drafts -> {
|
||||
|
||||
assert drafts != null;
|
||||
if(drafts.size() > 0) {
|
||||
|
||||
draftsList_.clear();
|
||||
noData.setVisibility(View.GONE);
|
||||
draftsList_.addAll(drafts);
|
||||
adapter.notifyDataSetChanged();
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
draftsList_.clear();
|
||||
fetchDataAsync(currentActiveAccountId);
|
||||
}
|
||||
|
||||
public void deleteAllDrafts(int accountId) {
|
||||
|
||||
if(draftsList_.size() > 0) {
|
||||
|
||||
DraftsApi.deleteAllDrafts(accountId);
|
||||
draftsList_.clear();
|
||||
adapter.notifyDataSetChanged();
|
||||
Toasty.info(ctx, getResources().getString(R.string.draftsDeleteSuccess));
|
||||
|
||||
}
|
||||
else {
|
||||
Toasty.error(ctx, getResources().getString(R.string.draftsListEmpty));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
|
||||
|
||||
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user