Skip to content

Commit

Permalink
Merge pull request #24 from SlaVcE14/dev
Browse files Browse the repository at this point in the history
Update branch
  • Loading branch information
SlaVcE14 authored Feb 2, 2024
2 parents 88ce83b + 039575b commit 6537ee5
Show file tree
Hide file tree
Showing 23 changed files with 974 additions and 72 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
applicationId "com.sjapps.jsonlist"
minSdk 23
targetSdk 34
versionCode 5
versionCode 8
versionName "1.4"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
16 changes: 15 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
android:largeHeap="true"
android:theme="@style/Theme.JsonList">
<activity android:name="com.sjapps.about.AboutActivity"/>
<activity
android:name="com.sjapps.logs.LogActivity"
android:exported="false" />
<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout"
android:exported="true">
<meta-data android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.OPEN_DOCUMENT"/>

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Expand All @@ -42,6 +46,16 @@
<data android:scheme="content" />
</intent-filter>
</activity>

<provider
android:authorities="${applicationId}.logs.provider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_path"/>
</provider>
</application>

</manifest>
197 changes: 157 additions & 40 deletions app/src/main/java/com/sjapps/adapters/ListAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,100 @@
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.graphics.Color;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.AnimRes;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.sjapps.jsonlist.java.JsonData;
import com.sjapps.jsonlist.java.ListItem;
import com.sjapps.jsonlist.MainActivity;
import com.sjapps.jsonlist.R;

import java.util.ArrayList;

public class ListAdapter extends BaseAdapter {
public class ListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

Handler handler = new Handler();

ArrayList<ListItem> list;
Context context;
MainActivity activity;
String path;
public int selectedItem = -1;
public int highlightedItem = -1;



static class ViewHolderShort extends RecyclerView.ViewHolder{

TextView title;

public ViewHolderShort(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.itemName);
}
public TextView getTitleTxt(){
return title;
}

public View getView(){
return itemView;
}

}

static class ViewHolderLong extends RecyclerView.ViewHolder{

TextView title, value;

public ViewHolderLong(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.itemName);
value = itemView.findViewById(R.id.itemValue);
}
public TextView getTitleTxt(){
return title;
}

public TextView getValueTxt(){
return value;
}

public View getView(){
return itemView;
}

}

static class ViewHolderSpace extends RecyclerView.ViewHolder{


public ViewHolderSpace(View itemView) {
super(itemView);

}

public View getView(){
return itemView;
}

}


public ListAdapter(ArrayList<ListItem> list, Context context,String path){
this.list = list;
Expand All @@ -33,70 +106,82 @@ public ListAdapter(ArrayList<ListItem> list, Context context,String path){
}

@Override
public int getCount() {
if (list == null)
return 0;

if (list.size() == 0)
return 0;
public int getItemViewType(int position) {

if (!list.get(getLast()).isSpace())
return list.size();
return getLast();
}
ListItem item = list.get(position);

@Override
public Object getItem(int i) {
return list.get(i);
return (item.isArray() || item.isObject())?0:item.isSpace()?2:1;
}

@NonNull
@Override
public long getItemId(int i) {
return i;
}

private int getLast(){
return (list.size()>0?list.size()-1:0);
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
switch (viewType) {
case 0:
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_layout,parent,false);
return new ViewHolderShort(view);
case 1:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_layout2,parent,false);
return new ViewHolderLong(view);
case 2:
view = LayoutInflater.from(parent.getContext()).inflate(R.layout.space_layout,parent,false);
return new ViewHolderSpace(view);
}
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_layout,parent,false);
return new ViewHolderShort(view);
}


@Override
public View getView(int position, View convertView, ViewGroup parent) {
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int pos) {

ListItem item = list.get(position);
ListItem item = list.get(pos);
if(item.isSpace()) {
return LayoutInflater.from(context).inflate(R.layout.space_layout, parent, false);
return;
}

int position = pos;

if (item.isArray() || item.isObject()) {

View view = LayoutInflater.from(context).inflate(R.layout.list_layout,parent,false);
TextView titleTxt = view.findViewById(R.id.itemName);
ViewHolderShort currentHolder = (ViewHolderShort) holder;

TextView titleTxt = currentHolder.getTitleTxt();
titleTxt.setText(item.getName());

View view = currentHolder.getView();

if (selectedItem == position){
view.findViewById(R.id.copyBtn).setVisibility(View.VISIBLE);
}else view.findViewById(R.id.copyBtn).setVisibility(View.GONE);

if (highlightedItem == position){
setAnimation(context,view,R.anim.button_prev,new OvershootInterpolator());
highlightedItem = -1;
}

String newPath = path + (path.equals("") ? "": "///" + (item.getId()!=-1?"{" + item.getId() + "}":"")) + item.getName();
view.findViewById(R.id.btn).setOnClickListener(view1 -> activity.open(JsonData.getPathFormat(newPath),newPath));
view.findViewById(R.id.btn).setOnClickListener(view1 -> activity.open(JsonData.getPathFormat(newPath),newPath,position));
view.findViewById(R.id.copyBtn).setOnClickListener(v -> {
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clipData = ClipData.newPlainText("Text",item.getName());
clipboard.setPrimaryClip(clipData);
Toast.makeText(v.getContext(),"Copied to clipboard",Toast.LENGTH_SHORT).show();
selectedItem = -1;
notifyDataSetChanged();
ClipData clipData = ClipData.newPlainText("Text",item.getName());
clipboard.setPrimaryClip(clipData);
Toast.makeText(v.getContext(),"Copied to clipboard",Toast.LENGTH_SHORT).show();
selectedItem = -1;
notifyItemChanged(position);
});
view.findViewById(R.id.btn).setOnLongClickListener(v -> {
notifyItemChanged(selectedItem);
selectedItem = position;
notifyDataSetChanged();
notifyItemChanged(position);
return true;
});
return view;

return;
}
View view = LayoutInflater.from(context).inflate(R.layout.list_layout2,parent,false);
TextView titleTxt = view.findViewById(R.id.itemName);
TextView valueTxt = view.findViewById(R.id.itemValue);

ViewHolderLong currentHolder = (ViewHolderLong) holder;
View view = currentHolder.getView();
TextView titleTxt = currentHolder.getTitleTxt();
TextView valueTxt = currentHolder.getValueTxt();
if (item.getName() == null)
titleTxt.setVisibility(View.GONE);
else {
Expand All @@ -107,6 +192,38 @@ public View getView(int position, View convertView, ViewGroup parent) {

valueTxt.setText(item.getValue().isEmpty() ? "\"\"" : item.getValue());

return view;
}

@Override
public int getItemCount() {
if (list == null)
return 0;

if (list.size() == 0)
return 0;

if (!list.get(getLast()).isSpace())
return list.size();
return getLast();
}

private int getLast(){
return (list.size()>0?list.size()-1:0);
}

@Override
public long getItemId(int position) {
return position;
}

public void setHighlightItem(int position){
highlightedItem = position;
}

public static void setAnimation(Context context, @NonNull View view, @AnimRes int animationRes, Interpolator interpolator) {
Animation animation = AnimationUtils.loadAnimation(context, animationRes);
if (interpolator != null)
animation.setInterpolator(interpolator);
view.startAnimation(animation);
}
}
30 changes: 30 additions & 0 deletions app/src/main/java/com/sjapps/jsonlist/AppState.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sjapps.jsonlist;

public class AppState {
boolean hasNewCrash;
boolean hasCrashLogs;

public boolean hasNewCrash() {
return hasNewCrash;
}

public void setHasNewCrash(boolean hasNewCrash) {
this.hasNewCrash = hasNewCrash;
}

public boolean hasCrashLogs() {
return hasCrashLogs;
}

public void setHasCrashLogs(boolean hasCrashLogs) {
this.hasCrashLogs = hasCrashLogs;
}

@Override
public String toString() {
return "AppState{" +
"hasNewCrash=" + hasNewCrash +
", hasCrashLogs=" + hasCrashLogs +
'}';
}
}
Loading

0 comments on commit 6537ee5

Please sign in to comment.