Browse Source

implemented sub dir view

tags/2.2.0
M M Arif 4 weeks ago
parent
commit
d7b1a226d0
10 changed files with 149 additions and 65 deletions
  1. +1
    -0
      README.md
  2. +2
    -0
      app/build.gradle
  3. +2
    -0
      app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java
  4. +11
    -10
      app/src/main/java/org/mian/gitnex/adapters/FilesAdapter.java
  5. +97
    -21
      app/src/main/java/org/mian/gitnex/fragments/FilesFragment.java
  6. +9
    -6
      app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java
  7. +6
    -3
      app/src/main/res/layout/activity_file_view.xml
  8. +1
    -1
      app/src/main/res/layout/files_list.xml
  9. +19
    -24
      app/src/main/res/layout/fragment_files.xml
  10. +1
    -0
      app/src/main/res/values/strings.xml

+ 1
- 0
README.md View File

@@ -83,5 +83,6 @@ Open source libraries
- Abumoallim/android-multi-select-dialog
- Pes/materialcolorpicker
- Hendraanggrian/socialview
- Fython/BreadcrumbsView

[Follow me on Fediverse - mastodon.social/@mmarif](https://mastodon.social/@mmarif)

+ 2
- 0
app/build.gradle View File

@@ -68,4 +68,6 @@ dependencies {

implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"

implementation "com.github.HamidrezaAmz:BreadcrumbsView:0.2.9"
}

+ 2
- 0
app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java View File

@@ -2,6 +2,7 @@ package org.mian.gitnex.activities;

import android.content.Context;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
@@ -58,6 +59,7 @@ public class FileViewActivity extends AppCompatActivity {
String singleFileName = getIntent().getStringExtra("singleFileName");

TextView toolbar_title = findViewById(R.id.toolbar_title);
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
toolbar_title.setText(singleFileName);

initCloseListener();

+ 11
- 10
app/src/main/java/org/mian/gitnex/adapters/FilesAdapter.java View File

@@ -1,7 +1,6 @@
package org.mian.gitnex.adapters;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -12,10 +11,8 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.FileViewActivity;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Files;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;

@@ -29,6 +26,13 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
private Context mCtx;
private List<Files> filesListFull;

private FilesAdapterListener filesListener;

public interface FilesAdapterListener {
void onClickDir(String str);
void onClickFile(String str);
}

class FilesViewHolder extends RecyclerView.ViewHolder {

private ImageView fileTypeImage;
@@ -49,16 +53,12 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
public void onClick(View v) {

Context context = v.getContext();
TinyDB tinyDb = new TinyDB(context);

if(fileType.getText().toString().equals("file")) {
Intent intent = new Intent(context, FileViewActivity.class);
intent.putExtra("singleFileName", fileName.getText().toString());
context.startActivity(intent);
filesListener.onClickFile(fileName.getText().toString());
}
else if(fileType.getText().toString().equals("dir")) {
//tinyDb.putString("filesDir", fileName.getText().toString());
Toasty.info(context, context.getString(R.string.filesDirNotSupportedYet));
filesListener.onClickDir(fileName.getText().toString());
}
else {
Toasty.info(context, context.getString(R.string.filesGenericError));
@@ -134,10 +134,11 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
}
}

public FilesAdapter(Context mCtx, List<Files> filesListMain) {
public FilesAdapter(Context mCtx, List<Files> filesListMain, FilesAdapterListener filesListener) {
this.mCtx = mCtx;
this.filesList = filesListMain;
filesListFull = new ArrayList<>(filesList);
this.filesListener = filesListener;
}

@NonNull

+ 97
- 21
app/src/main/java/org/mian/gitnex/fragments/FilesFragment.java View File

@@ -1,5 +1,6 @@
package org.mian.gitnex.fragments;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
@@ -10,8 +11,6 @@ import androidx.lifecycle.ViewModelProvider;
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;
@@ -23,29 +22,36 @@ import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.FileViewActivity;
import org.mian.gitnex.adapters.FilesAdapter;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.models.Files;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.viewmodels.FilesViewModel;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import moe.feng.common.view.breadcrumbs.BreadcrumbsView;
import moe.feng.common.view.breadcrumbs.DefaultBreadcrumbsCallback;
import moe.feng.common.view.breadcrumbs.model.BreadcrumbItem;

/**
* Author M M Arif
*/

public class FilesFragment extends Fragment {
public class FilesFragment extends Fragment implements FilesAdapter.FilesAdapterListener {

private ProgressBar mProgressBar;
private FilesAdapter adapter;
private RecyclerView mRecyclerView;
private TextView noDataFiles;
private LinearLayout filesFrame;
private TextView fileStructure;
private static String repoNameF = "param2";
private static String repoOwnerF = "param1";
private boolean initialLoad = true;
private BreadcrumbsView mBreadcrumbsView;

private String repoName;
private String repoOwner;
@@ -88,53 +94,118 @@ public class FilesFragment extends Fragment {
noDataFiles = v.findViewById(R.id.noDataFiles);
filesFrame = v.findViewById(R.id.filesFrame);

final SwipeRefreshLayout swipeRefresh = v.findViewById(R.id.pullToRefresh);

fileStructure = v.findViewById(R.id.fileStructure);
mRecyclerView = v.findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

String filesDirDB = tinyDb.getString("filesDir");

DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
DividerItemDecoration.VERTICAL);
mRecyclerView.addItemDecoration(dividerItemDecoration);

mProgressBar = v.findViewById(R.id.progress_bar);

swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
mBreadcrumbsView = v.findViewById(R.id.breadcrumbs_view);
mBreadcrumbsView.setItems(new ArrayList<>(Arrays.asList(
BreadcrumbItem.createSimpleItem(getResources().getString(R.string.filesBreadcrumbRoot))
)));

fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName);

return v;
}

@Override
public void onResume() {
super.onResume();
}

private static BreadcrumbItem createItem(String title) {
List<String> list = new ArrayList<>();
list.add(title);
return new BreadcrumbItem(list);
}

@Override
public void onClickDir(String dirName) {

TinyDB tinyDb = new TinyDB(getContext());
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");

StringBuilder breadcrumbBuilder = new StringBuilder();

breadcrumbBuilder.append(fileStructure.getText().toString()).append("/").append(dirName);

fileStructure.setText(breadcrumbBuilder);

mBreadcrumbsView.addItem(createItem(dirName));
mBreadcrumbsView.setCallback(new DefaultBreadcrumbsCallback<BreadcrumbItem>() {
@Override
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
swipeRefresh.setRefreshing(false);
FilesViewModel.loadFilesList(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName);
}
}, 200);
public void onNavigateBack(BreadcrumbItem item, int position) {

if(position == 0) {
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName);
fileStructure.setText("");
return;
}

String filterDir = fileStructure.getText().toString();
String result = filterDir.substring(0, filterDir.indexOf(item.getSelectedItem()));
fileStructure.setText(result + item.getSelectedItem());
fetchDataAsyncSub(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, fileStructure.getText().toString());

}

@Override
public void onNavigateNewLocation(BreadcrumbItem newItem, int changedPosition) {

}
});

fetchDataAsyncSub(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName, fileStructure.getText().toString());

fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName);
}

return v;
@Override
public void onClickFile(String fileName) {

Intent intent = new Intent(getContext(), FileViewActivity.class);

if(!fileStructure.getText().toString().equals("Root")) {

intent.putExtra("singleFileName", fileStructure.getText().toString()+"/"+fileName);
}
else {

intent.putExtra("singleFileName", fileName);
}

Objects.requireNonNull(getContext()).startActivity(intent);
}

private void fetchDataAsync(String instanceUrl, String instanceToken, String owner, String repo) {

mRecyclerView.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);

FilesViewModel filesModel = new ViewModelProvider(this).get(FilesViewModel.class);

filesModel.getFilesList(instanceUrl, instanceToken, owner, repo).observe(this, new Observer<List<Files>>() {
@Override
public void onChanged(@Nullable List<Files> filesListMain) {
adapter = new FilesAdapter(getContext(), filesListMain);
adapter = new FilesAdapter(getContext(), filesListMain, FilesFragment.this);

mBreadcrumbsView.removeItemAfter(1);
if(adapter.getItemCount() > 0) {
mRecyclerView.setVisibility(View.VISIBLE);
mRecyclerView.setAdapter(adapter);
filesFrame.setVisibility(View.VISIBLE);
noDataFiles.setVisibility(View.GONE);
}
else {
mRecyclerView.setVisibility(View.VISIBLE);
adapter.notifyDataSetChanged();
mRecyclerView.setAdapter(adapter);
filesFrame.setVisibility(View.VISIBLE);
@@ -149,18 +220,23 @@ public class FilesFragment extends Fragment {

private void fetchDataAsyncSub(String instanceUrl, String instanceToken, String owner, String repo, String filesDir) {

mRecyclerView.setVisibility(View.GONE);
mProgressBar.setVisibility(View.VISIBLE);

FilesViewModel filesModel2 = new ViewModelProvider(this).get(FilesViewModel.class);

filesModel2.getFilesList2(instanceUrl, instanceToken, owner, repo, filesDir).observe(this, new Observer<List<Files>>() {
@Override
public void onChanged(@Nullable List<Files> filesListMain2) {
adapter = new FilesAdapter(getContext(), filesListMain2);
adapter = new FilesAdapter(getContext(), filesListMain2, FilesFragment.this);
if(adapter.getItemCount() > 0) {
mRecyclerView.setVisibility(View.VISIBLE);
mRecyclerView.setAdapter(adapter);
filesFrame.setVisibility(View.VISIBLE);
noDataFiles.setVisibility(View.GONE);
}
else {
mRecyclerView.setVisibility(View.VISIBLE);
adapter.notifyDataSetChanged();
mRecyclerView.setAdapter(adapter);
filesFrame.setVisibility(View.VISIBLE);

+ 9
- 6
app/src/main/java/org/mian/gitnex/viewmodels/FilesViewModel.java View File

@@ -86,12 +86,15 @@ public class FilesViewModel extends ViewModel {
@Override
public void onResponse(@NonNull Call<List<Files>> call, @NonNull Response<List<Files>> response) {

Collections.sort(response.body(), new Comparator<Files>() {
@Override
public int compare(Files byType1, Files byType2) {
return byType1.getType().compareTo(byType2.getType());
}
});
assert response.body() != null;
if(response.body().size() > 0) {
Collections.sort(response.body(), new Comparator<Files>() {
@Override
public int compare(Files byType1, Files byType2) {
return byType1.getType().compareTo(byType2.getType());
}
});
}

if (response.isSuccessful()) {
filesList.postValue(response.body());

+ 6
- 3
app/src/main/res/layout/activity_file_view.xml View File

@@ -35,8 +35,11 @@
android:layout_gravity="center_vertical"
android:text="@string/defaultFilename"
android:textColor="@color/white"
android:maxLines="1"
android:textSize="20sp" />
android:ellipsize="none"
android:scrollbars="horizontal"
android:singleLine="true"
android:layout_marginEnd="20dp"
android:textSize="18sp" />

</androidx.appcompat.widget.Toolbar>

@@ -58,7 +61,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorWhite"
android:textSize="16sp"
android:textSize="14sp"
android:padding="15dp"
/>


+ 1
- 1
app/src/main/res/layout/files_list.xml View File

@@ -25,7 +25,7 @@
android:layout_height="28dp"
android:layout_marginEnd="15dp"
android:contentDescription="@string/repoContentAvatar"
android:src="@drawable/ic_android" />
android:src="@drawable/ic_file" />

<LinearLayout
android:id="@+id/infoSection"

+ 19
- 24
app/src/main/res/layout/fragment_files.xml View File

@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".activities.RepoDetailActivity">

@@ -16,32 +16,27 @@
>

<TextView
android:id="@+id/fileBrowserBreadcrumb"
android:layout_width="match_parent"
android:id="@+id/fileStructure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_marginTop="20dp"
android:layout_marginBottom="10dp"
android:layout_marginStart="15dp"
android:layout_marginEnd="15dp"
android:textColor="@color/lightGray"
android:text="@string/filesBreadcrumb" />
android:visibility="gone"/>

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/pullToRefresh"
<moe.feng.common.view.breadcrumbs.BreadcrumbsView
android:id="@+id/breadcrumbs_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:padding="4dp"
android:scrollbars="vertical"
/>
android:layout_height="wrap_content"
app:CustomTextSize="16sp"
app:SelectedTextColor="@color/colorAccent"
app:UnSelectedTextColor="@color/lightGray"
android:text="@string/filesBreadcrumbRoot"/>

</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimary"
android:padding="4dp"
android:scrollbars="vertical" />

<TextView
android:id="@+id/noDataFiles"

+ 1
- 0
app/src/main/res/values/strings.xml View File

@@ -512,5 +512,6 @@
<string name="unWatchRepository">Unwatch Repository</string>
<string name="watchRepositorySuccess">Repository added to watch list</string>
<string name="unWatchRepositorySuccess">Repository removed from watch list</string>
<string name="filesBreadcrumbRoot" translatable="false">Root</string>

</resources>

Loading…
Cancel
Save