mirror of
https://codeberg.org/gitnex/GitNex
synced 2025-03-12 17:40:11 +01:00
Added reading file contentts
This commit is contained in:
parent
21097da995
commit
b90b3c3320
@ -11,8 +11,11 @@
|
|||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.NewFileActivity"
|
android:name=".activities.FileViewActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBar"></activity>
|
android:theme="@style/AppTheme.NoActionBar"></activity>
|
||||||
|
<activity
|
||||||
|
android:name=".activities.NewFileActivity"
|
||||||
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".activities.RepoWatchersActivity"
|
android:name=".activities.RepoWatchersActivity"
|
||||||
android:theme="@style/AppTheme.NoActionBar" />
|
android:theme="@style/AppTheme.NoActionBar" />
|
||||||
@ -64,8 +67,8 @@
|
|||||||
<activity android:name=".activities.NewOrganizationActivity" />
|
<activity android:name=".activities.NewOrganizationActivity" />
|
||||||
<activity android:name=".activities.OpenRepoInBrowserActivity" />
|
<activity android:name=".activities.OpenRepoInBrowserActivity" />
|
||||||
</application>
|
</application>
|
||||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
@ -0,0 +1,147 @@
|
|||||||
|
package org.mian.gitnex.activities;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ProgressBar;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.clients.RetrofitClient;
|
||||||
|
import org.mian.gitnex.helpers.AlertDialogs;
|
||||||
|
import org.mian.gitnex.helpers.Toasty;
|
||||||
|
import org.mian.gitnex.models.Files;
|
||||||
|
import org.mian.gitnex.util.AppUtil;
|
||||||
|
import org.mian.gitnex.util.TinyDB;
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author M M Arif
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class FileViewActivity extends AppCompatActivity {
|
||||||
|
|
||||||
|
private View.OnClickListener onClickListener;
|
||||||
|
private TextView singleFileContents;
|
||||||
|
final Context ctx = this;
|
||||||
|
private ProgressBar mProgressBar;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_file_view);
|
||||||
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
|
final TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||||
|
String repoFullName = tinyDb.getString("repoFullName");
|
||||||
|
String[] parts = repoFullName.split("/");
|
||||||
|
final String repoOwner = parts[0];
|
||||||
|
final String repoName = parts[1];
|
||||||
|
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||||
|
final String loginUid = tinyDb.getString("loginUid");
|
||||||
|
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||||
|
|
||||||
|
boolean connToInternet = AppUtil.haveNetworkConnection(getApplicationContext());
|
||||||
|
|
||||||
|
ImageView closeActivity = findViewById(R.id.close);
|
||||||
|
singleFileContents = findViewById(R.id.singleFileContents);
|
||||||
|
singleFileContents.setVisibility(View.GONE);
|
||||||
|
mProgressBar = findViewById(R.id.progress_bar);
|
||||||
|
|
||||||
|
String singleFileName = getIntent().getStringExtra("singleFileName");
|
||||||
|
|
||||||
|
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
||||||
|
toolbar_title.setText(singleFileName);
|
||||||
|
|
||||||
|
initCloseListener();
|
||||||
|
closeActivity.setOnClickListener(onClickListener);
|
||||||
|
|
||||||
|
if(connToInternet) {
|
||||||
|
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Toasty.info(getApplicationContext(), getString(R.string.checkNetConnection));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getSingleFileContents(String instanceUrl, String token, final String owner, String repo, final String filename) {
|
||||||
|
|
||||||
|
Call<Files> call = RetrofitClient
|
||||||
|
.getInstance(instanceUrl)
|
||||||
|
.getApiInterface()
|
||||||
|
.getSingleFileContents(token, owner, repo, filename);
|
||||||
|
|
||||||
|
call.enqueue(new Callback<Files>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResponse(@NonNull Call<Files> call, @NonNull retrofit2.Response<Files> response) {
|
||||||
|
|
||||||
|
if (response.code() == 200) {
|
||||||
|
|
||||||
|
AppUtil appUtil = new AppUtil();
|
||||||
|
assert response.body() != null;
|
||||||
|
|
||||||
|
if(!response.body().getContent().equals("")) {
|
||||||
|
singleFileContents.setVisibility(View.VISIBLE);
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
|
singleFileContents.setText(appUtil.decodeBase64(response.body().getContent()));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
singleFileContents.setText("");
|
||||||
|
mProgressBar.setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(response.code() == 401) {
|
||||||
|
|
||||||
|
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||||
|
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(response.code() == 403) {
|
||||||
|
|
||||||
|
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
|
||||||
|
|
||||||
|
}
|
||||||
|
else if(response.code() == 404) {
|
||||||
|
|
||||||
|
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
Toasty.info(getApplicationContext(), getString(R.string.labelGeneralError));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<Files> call, @NonNull Throwable t) {
|
||||||
|
Log.e("onFailure", t.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initCloseListener() {
|
||||||
|
onClickListener = new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View view) {
|
||||||
|
getIntent().removeExtra("singleFileName");
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,8 @@
|
|||||||
package org.mian.gitnex.adapters;
|
package org.mian.gitnex.adapters;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -11,6 +13,7 @@ import android.widget.TextView;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import org.mian.gitnex.R;
|
import org.mian.gitnex.R;
|
||||||
|
import org.mian.gitnex.activities.FileViewActivity;
|
||||||
import org.mian.gitnex.models.Files;
|
import org.mian.gitnex.models.Files;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -29,26 +32,32 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
|||||||
|
|
||||||
private ImageView fileTypeImage;
|
private ImageView fileTypeImage;
|
||||||
private TextView fileName;
|
private TextView fileName;
|
||||||
|
private TextView fileType;
|
||||||
|
|
||||||
private FilesViewHolder(View itemView) {
|
private FilesViewHolder(View itemView) {
|
||||||
|
|
||||||
super(itemView);
|
super(itemView);
|
||||||
fileName = itemView.findViewById(R.id.fileName);
|
fileName = itemView.findViewById(R.id.fileName);
|
||||||
fileTypeImage = itemView.findViewById(R.id.fileImage);
|
fileTypeImage = itemView.findViewById(R.id.fileImage);
|
||||||
|
fileType = itemView.findViewById(R.id.fileType);
|
||||||
|
|
||||||
/*ImageView filesDropdownMenu = itemView.findViewById(R.id.filesDropdownMenu);
|
//ImageView filesDropdownMenu = itemView.findViewById(R.id.filesDropdownMenu);
|
||||||
|
|
||||||
itemView.setOnClickListener(new View.OnClickListener() {
|
itemView.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
Context context = v.getContext();
|
Context context = v.getContext();
|
||||||
|
Intent intent = new Intent(context, FileViewActivity.class);
|
||||||
|
intent.putExtra("singleFileName", fileName.getText().toString());
|
||||||
|
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
filesDropdownMenu.setOnClickListener(new View.OnClickListener() {
|
|
||||||
|
/*filesDropdownMenu.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
|
|
||||||
@ -132,6 +141,7 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
|||||||
|
|
||||||
Files currentItem = filesList.get(position);
|
Files currentItem = filesList.get(position);
|
||||||
|
|
||||||
|
holder.fileType.setText(currentItem.getType());
|
||||||
holder.fileName.setText(currentItem.getName());
|
holder.fileName.setText(currentItem.getName());
|
||||||
|
|
||||||
if(currentItem.getType().equals("file")) {
|
if(currentItem.getType().equals("file")) {
|
||||||
@ -140,6 +150,9 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
|
|||||||
else if(currentItem.getType().equals("dir")) {
|
else if(currentItem.getType().equals("dir")) {
|
||||||
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_folder_24));
|
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_folder_24));
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_question_mark_24));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,6 +216,9 @@ public interface ApiInterface {
|
|||||||
@POST("repos/{owner}/{repo}/contents/{file}") // create new file
|
@POST("repos/{owner}/{repo}/contents/{file}") // create new file
|
||||||
Call<JsonElement> createNewFile(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Path("file") String fileName, @Body NewFile jsonStr);
|
Call<JsonElement> createNewFile(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Path("file") String fileName, @Body NewFile jsonStr);
|
||||||
|
|
||||||
@GET("repos/{owner}/{repo}/contents") // get all files and dirs
|
@GET("repos/{owner}/{repo}/contents") // get all the files and dirs of a repository
|
||||||
Call<List<Files>> getFiles(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
Call<List<Files>> getFiles(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName);
|
||||||
|
|
||||||
|
@GET("repos/{owner}/{repo}/contents/{file}") // get single file contents
|
||||||
|
Call<Files> getSingleFileContents(@Header("Authorization") String token, @Path("owner") String ownerName, @Path("repo") String repoName, @Path("file") String file);
|
||||||
}
|
}
|
5
app/src/main/res/drawable/ic_question_mark_24.xml
Normal file
5
app/src/main/res/drawable/ic_question_mark_24.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<vector android:height="24dp" android:tint="#FFFFFF"
|
||||||
|
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
||||||
|
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="#FF000000" android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM13,19h-2v-2h2v2zM15.07,11.25l-0.9,0.92C13.45,12.9 13,13.5 13,15h-2v-0.5c0,-1.1 0.45,-2.1 1.17,-2.83l1.24,-1.26c0.37,-0.36 0.59,-0.86 0.59,-1.41 0,-1.1 -0.9,-2 -2,-2s-2,0.9 -2,2L8,9c0,-2.21 1.79,-4 4,-4s4,1.79 4,4c0,0.88 -0.36,1.68 -0.93,2.25z"/>
|
||||||
|
</vector>
|
78
app/src/main/res/layout/activity_file_view.xml
Normal file
78
app/src/main/res/layout/activity_file_view.xml
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:orientation="vertical"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:background="@color/colorPrimary">
|
||||||
|
|
||||||
|
<com.google.android.material.appbar.AppBarLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar
|
||||||
|
android:id="@+id/toolbar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="?attr/colorPrimary"
|
||||||
|
tools:ignore="UnusedAttribute">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/close"
|
||||||
|
android:layout_width="30dp"
|
||||||
|
android:layout_height="30dp"
|
||||||
|
android:layout_marginRight="15dp"
|
||||||
|
android:layout_marginLeft="15dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:contentDescription="@string/close"
|
||||||
|
android:src="@drawable/ic_close" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/toolbar_title"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
android:text="@string/defaultFilename"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textSize="20sp" />
|
||||||
|
|
||||||
|
</androidx.appcompat.widget.Toolbar>
|
||||||
|
|
||||||
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_marginTop="50dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:background="@color/toastBackground">
|
||||||
|
|
||||||
|
<ScrollView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:ignore="UselessParent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/singleFileContents"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/colorWhite"
|
||||||
|
android:textSize="16sp"
|
||||||
|
android:padding="15dp"
|
||||||
|
/>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<ProgressBar
|
||||||
|
android:id="@+id/progress_bar"
|
||||||
|
style="@style/Base.Widget.AppCompat.ProgressBar"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:indeterminate="true"
|
||||||
|
android:visibility="visible" />
|
||||||
|
|
||||||
|
</RelativeLayout>
|
@ -14,6 +14,12 @@
|
|||||||
android:background="@color/backgroundColor"
|
android:background="@color/backgroundColor"
|
||||||
tools:context=".activities.MainActivity">
|
tools:context=".activities.MainActivity">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/fileType"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:visibility="invisible"/>
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/fileImage"
|
android:id="@+id/fileImage"
|
||||||
android:layout_width="28dp"
|
android:layout_width="28dp"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user