diff --git a/app/src/main/java/org/mian/gitnex/activities/BaseActivity.java b/app/src/main/java/org/mian/gitnex/activities/BaseActivity.java index b08d9223..0a7f1b6e 100644 --- a/app/src/main/java/org/mian/gitnex/activities/BaseActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/BaseActivity.java @@ -31,23 +31,25 @@ public abstract class BaseActivity extends AppCompatActivity { final TinyDB tinyDb = new TinyDB(getApplicationContext()); - if(tinyDb.getInt("themeId") == 1) { - setTheme(R.style.AppThemeLight); - } - else if(tinyDb.getInt("themeId") == 2) { + switch(tinyDb.getInt("themeId")) { - boolean timeSetterFlag = TimeHelper.timeBetweenHours(18, 6); // 6pm to 6am - - if(timeSetterFlag) { - setTheme(R.style.AppTheme); - } - else { + case 1: setTheme(R.style.AppThemeLight); - } + break; + + case 2: + if(TimeHelper.timeBetweenHours(18, 6)) { // 6pm to 6am + setTheme(R.style.AppTheme); + } + else { + setTheme(R.style.AppThemeLight); + } + break; + + default: + setTheme(R.style.AppTheme); + break; - } - else { - setTheme(R.style.AppTheme); } String appLocale = tinyDb.getString("locale"); diff --git a/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java b/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java index f62891f3..bb8ddeee 100644 --- a/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/FileDiffActivity.java @@ -4,12 +4,11 @@ import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.ImageView; +import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.Toolbar; -import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import org.apache.commons.io.FileUtils; import org.mian.gitnex.R; import org.mian.gitnex.adapters.FilesDiffAdapter; @@ -34,7 +33,7 @@ public class FileDiffActivity extends BaseActivity { private View.OnClickListener onClickListener; private TextView toolbar_title; - private RecyclerView mRecyclerView; + private ListView mListView; private ProgressBar mProgressBar; @Override @@ -60,11 +59,10 @@ public class FileDiffActivity extends BaseActivity { ImageView closeActivity = findViewById(R.id.close); toolbar_title = findViewById(R.id.toolbar_title); - mRecyclerView = findViewById(R.id.recyclerView); + mListView = findViewById(R.id.listView); mProgressBar = findViewById(R.id.progress_bar); - mRecyclerView.setHasFixedSize(true); - mRecyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + mListView.setDivider(null); toolbar_title.setText(R.string.processingText); initCloseListener(); @@ -113,18 +111,18 @@ public class FileDiffActivity extends BaseActivity { String[] fileContents_ = level2nd[1].split("@@"); // file info / content part String fileInfoFinal = fileContents_[0]; - String fileContentsFinal = (fileContents_[1]); + StringBuilder fileContentsFinal = new StringBuilder(fileContents_[1]); if(level2nd.length > 2) { for (int j = 2; j < level2nd.length; j++) { - fileContentsFinal += (level2nd[j]); + fileContentsFinal.append(level2nd[j]); } } String fileExtension = FileUtils.getExtension(fileNameFinal); - String fileContentsFinalWithBlankLines = fileContentsFinal.replaceAll( ".*@@.*", "" ); - String fileContentsFinalWithoutBlankLines = fileContentsFinal.replaceAll( ".*@@.*(\r?\n|\r)?", "" ); + String fileContentsFinalWithBlankLines = fileContentsFinal.toString().replaceAll( ".*@@.*", "" ); + String fileContentsFinalWithoutBlankLines = fileContentsFinal.toString().replaceAll( ".*@@.*(\r?\n|\r)?", "" ); fileContentsFinalWithoutBlankLines = fileContentsFinalWithoutBlankLines.replaceAll( ".*\\ No newline at end of file.*(\r?\n|\r)?", "" ); fileContentsArray.add(new FileDiffView(fileNameFinal, appUtil.imageExtension(fileExtension), fileInfoFinal, fileContentsFinalWithoutBlankLines)); @@ -161,8 +159,8 @@ public class FileDiffActivity extends BaseActivity { toolbar_title.setText(getResources().getString(R.string.fileDiffViewHeaderSingle, Integer.toString(filesCount))); } - FilesDiffAdapter adapter = new FilesDiffAdapter(fileContentsArray, getApplicationContext()); - mRecyclerView.setAdapter(adapter); + FilesDiffAdapter adapter = new FilesDiffAdapter(FileDiffActivity.this, fileContentsArray); + mListView.setAdapter(adapter); mProgressBar.setVisibility(View.GONE); diff --git a/app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java b/app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java index 22069e3c..7e2314f7 100644 --- a/app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java @@ -83,20 +83,26 @@ public class ReplyToIssueActivity extends BaseActivity { replyButton = findViewById(R.id.replyButton); - if(getIntent().getStringExtra("commentAction") != null && getIntent().getStringExtra("commentAction").equals("edit")) { + if(getIntent().getStringExtra("commentBody") != null) { addComment.setText(getIntent().getStringExtra("commentBody")); + + if(getIntent().getBooleanExtra("cursorToEnd", false)) { + addComment.setSelection(addComment.length()); + } + + } + + if(getIntent().getStringExtra("commentAction") != null && getIntent().getStringExtra("commentAction").equals("edit")) { + final String commentId = getIntent().getStringExtra("commentId"); toolbar_title.setText(getResources().getString(R.string.editCommentTitle)); replyButton.setText(getResources().getString(R.string.editCommentButtonText)); - replyButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - disableProcessButton(); - IssueActions.editIssueComment(ctx, Integer.valueOf(commentId), addComment.getText().toString()); - } - + replyButton.setOnClickListener(v -> { + disableProcessButton(); + IssueActions.editIssueComment(ctx, Integer.parseInt(commentId), addComment.getText().toString()); }); return; diff --git a/app/src/main/java/org/mian/gitnex/adapters/FilesDiffAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/FilesDiffAdapter.java index 9c71c48a..4065af6a 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/FilesDiffAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/FilesDiffAdapter.java @@ -1,138 +1,267 @@ package org.mian.gitnex.adapters; +import android.annotation.SuppressLint; import android.content.Context; +import android.content.Intent; +import android.graphics.Typeface; +import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.HorizontalScrollView; +import android.widget.BaseAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; -import androidx.annotation.NonNull; -import androidx.recyclerview.widget.RecyclerView; import org.mian.gitnex.R; +import org.mian.gitnex.activities.ReplyToIssueActivity; +import org.mian.gitnex.helpers.DiffTextView; import org.mian.gitnex.models.FileDiffView; import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentSkipListMap; /** - * Author M M Arif + * Author opyale */ -public class FilesDiffAdapter extends RecyclerView.Adapter { +public class FilesDiffAdapter extends BaseAdapter { - private List dataList; - private Context ctx; + private static Map selectedViews; + private static final int MAXIMUM_LINES = 5000; - static class FilesDiffViewHolder extends RecyclerView.ViewHolder { + private static int COLOR_ADDED; + private static int COLOR_REMOVED; + private static int COLOR_NORMAL; + private static int COLOR_SELECTED; + private static int COLOR_FONT; - private TextView fileContents; - private TextView fileName; - private TextView fileInfo; - private ImageView fileImage; - private HorizontalScrollView fileContentsView; - private LinearLayout allLines; + private Context context; + private List fileDiffViews; - private FilesDiffViewHolder(View itemView) { - super(itemView); + public FilesDiffAdapter(Context context, List fileDiffViews) { - fileContents = itemView.findViewById(R.id.fileContents); - fileName = itemView.findViewById(R.id.fileName); - fileInfo = itemView.findViewById(R.id.fileInfo); - fileImage = itemView.findViewById(R.id.fileImage); - fileContentsView = itemView.findViewById(R.id.fileContentsView); - allLines = itemView.findViewById(R.id.allLinesLayout); + this.context = context; + this.fileDiffViews = fileDiffViews; - } - } + selectedViews = new ConcurrentSkipListMap<>(); - public FilesDiffAdapter(List dataListMain, Context ctx) { - this.dataList = dataListMain; - this.ctx = ctx; - } + COLOR_ADDED = getColorFromAttribute(R.attr.diffAddedColor); + COLOR_REMOVED = getColorFromAttribute(R.attr.diffRemovedColor); + COLOR_NORMAL = getColorFromAttribute(R.attr.primaryBackgroundColor); + COLOR_SELECTED = getColorFromAttribute(R.attr.diffSelectedColor); + COLOR_FONT = getColorFromAttribute(R.attr.inputTextColor); - @NonNull - @Override - public FilesDiffAdapter.FilesDiffViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { - View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_files_diffs, parent, false); - return new FilesDiffAdapter.FilesDiffViewHolder(v); - } + } - @Override - public void onBindViewHolder(@NonNull FilesDiffViewHolder holder, int position) { + @Override + public int getCount() { - FileDiffView data = dataList.get(position); + return fileDiffViews.size(); + } - if(data.isFileType()) { + @Override + public Object getItem(int position) { - holder.fileName.setText(data.getFileName()); + return fileDiffViews.get(position); + } - holder.fileInfo.setVisibility(View.GONE); + @Override + public long getItemId(int position) { - //byte[] imageData = Base64.decode(data.getFileContents(), Base64.DEFAULT); - //Drawable imageDrawable = new BitmapDrawable(ctx.getResources(), BitmapFactory.decodeByteArray(imageData, 0, imageData.length)); - //holder.fileImage.setImageDrawable(imageDrawable); - holder.fileContentsView.setVisibility(View.GONE); + return position; + } - } - else { + @SuppressLint({"ViewHolder", "InflateParams"}) + @Override + public View getView(int position, View convertView, ViewGroup parent) { - String[] splitData = data.getFileContents().split("\\R"); + convertView = LayoutInflater.from(context).inflate(R.layout.list_files_diffs, null, false); - for (String eachSplit : splitData) { + TextView headerFileName = convertView.findViewById(R.id.headerFileName); + TextView headerFileInfo = convertView.findViewById(R.id.headerFileInfo); + ImageView footerImage = convertView.findViewById(R.id.footerImage); + LinearLayout diffStats = convertView.findViewById(R.id.diff_stats); + LinearLayout diffLines = convertView.findViewById(R.id.diffLines); - TextView textLine = new TextView(ctx); - textLine.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); + FileDiffView data = (FileDiffView) getItem(position); + headerFileName.setText(data.getFileName()); - if (eachSplit.startsWith("+")) { + if(data.isFileType()) { - textLine.setText(eachSplit); - holder.allLines.addView(textLine); + diffStats.setVisibility(View.GONE); + diffLines.addView(getMessageView(context.getResources().getString(R.string.binaryFileError))); - textLine.setTextColor(ctx.getResources().getColor(R.color.colorPrimary)); - textLine.setPadding(5, 5, 5, 5); - textLine.setBackgroundColor(ctx.getResources().getColor(R.color.diffAddedColor)); + } + else { - } - else if (eachSplit.startsWith("-")) { + diffStats.setVisibility(View.VISIBLE); + headerFileInfo.setText(data.getFileInfo()); - textLine.setText(eachSplit); - holder.allLines.addView(textLine); + String[] codeLines = getLines(data.getFileContents()); - textLine.setTextColor(ctx.getResources().getColor(R.color.colorPrimary)); - textLine.setPadding(5, 5, 5, 5); - textLine.setBackgroundColor(ctx.getResources().getColor(R.color.diffRemovedColor)); + if(MAXIMUM_LINES > codeLines.length) { - } - else { + for(int l=0; l 0) { - textLine.setText(eachSplit); - holder.allLines.addView(textLine); + if(codeLines[l].length() > 0) { - textLine.setTextColor(ctx.getResources().getColor(R.color.colorPrimary)); - textLine.setPadding(5, 5, 5, 5); - textLine.setBackgroundColor(ctx.getResources().getColor(R.color.white)); - } + int uniquePosition = l + (position * MAXIMUM_LINES); - } + DiffTextView diffTextView = new DiffTextView(context); - } + diffTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); + diffTextView.setPadding(15, 2, 15, 2); + diffTextView.setTypeface(Typeface.createFromAsset(context.getAssets(), "fonts/sourcecodeproregular.ttf")); + diffTextView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + diffTextView.setPosition(uniquePosition); - holder.fileName.setText(data.getFileName()); - if(!data.getFileInfo().equals("")) { - holder.fileInfo.setText(ctx.getResources().getString(R.string.fileDiffInfoChanges, data.getFileInfo())); - } - else { - holder.fileInfo.setVisibility(View.GONE); - } + boolean isSelected = false; - } + for(View view : selectedViews.values()) { - } + if(((DiffTextView) view).getPosition() == uniquePosition) { - @Override - public int getItemCount() { - return dataList.size(); - } + diffTextView.setBackgroundColor(COLOR_SELECTED); + isSelected = true; + break; -} \ No newline at end of file + } + + } + + + if(codeLines[l].startsWith("+")) { + + diffTextView.setText(codeLines[l]); + diffTextView.setTextColor(COLOR_FONT); + + if(!isSelected) { + + diffTextView.setInitialBackgroundColor(COLOR_ADDED); + } + + } + else if(codeLines[l].startsWith("-")) { + + diffTextView.setText(codeLines[l]); + diffTextView.setTextColor(COLOR_FONT); + + if(!isSelected) { + + diffTextView.setInitialBackgroundColor(COLOR_REMOVED); + } + + } + else { + + diffTextView.setText(codeLines[l]); + diffTextView.setTextColor(COLOR_FONT); + + if(!isSelected) { + + diffTextView.setInitialBackgroundColor(COLOR_NORMAL); + } + + } + + + diffTextView.setOnClickListener(v -> { + + if(((DiffTextView) v).getCurrentBackgroundColor() != COLOR_SELECTED) { + + selectedViews.put(((DiffTextView) v).getPosition(), v); + v.setBackgroundColor(COLOR_SELECTED); + + } + else { + + selectedViews.remove(((DiffTextView) v).getPosition()); + v.setBackgroundColor(((DiffTextView) v).getInitialBackgroundColor()); + + } + + }); + + + diffTextView.setOnLongClickListener(v -> { + + if(((DiffTextView) v).getCurrentBackgroundColor() == COLOR_SELECTED) { + + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("```\n"); + + for(View view : selectedViews.values()) { + + stringBuilder.append(((DiffTextView) view).getText()); + stringBuilder.append("\n"); + + } + + stringBuilder.append("```\n\n"); + + selectedViews.clear(); + + Intent intent = new Intent(context, ReplyToIssueActivity.class); + intent.putExtra("commentBody", stringBuilder.toString()); + intent.putExtra("cursorToEnd", true); + intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + + context.startActivity(intent); + + } + + return true; + + }); + + diffLines.addView(diffTextView); + + } + + } + + } + else { + + diffLines.addView(getMessageView(context.getResources().getString(R.string.fileTooLarge))); + + } + + } + + return convertView; + + } + + private TextView getMessageView(String message) { + + TextView textView = new TextView(context); + + textView.setTextColor(COLOR_FONT); + textView.setBackgroundColor(COLOR_NORMAL); + textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); + textView.setPadding(15, 15, 15, 15); + textView.setTypeface(Typeface.DEFAULT); + textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)); + textView.setText(message); + + return textView; + + } + + private String[] getLines(String content) { + + return content.split("\\R"); + + } + + private int getColorFromAttribute(int resid) { + + TypedValue typedValue = new TypedValue(); + context.getTheme().resolveAttribute(resid, typedValue, true); + + return typedValue.data; + + } + +} diff --git a/app/src/main/java/org/mian/gitnex/helpers/DiffTextView.java b/app/src/main/java/org/mian/gitnex/helpers/DiffTextView.java new file mode 100644 index 00000000..dcb81e7a --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/helpers/DiffTextView.java @@ -0,0 +1,64 @@ +package org.mian.gitnex.helpers; + +import android.content.Context; +import android.util.AttributeSet; + +/** + * Author opyale + */ + +public class DiffTextView extends androidx.appcompat.widget.AppCompatTextView { + + private int initialBackgroundColor; + private int currentBackgroundColor; + private long position; + + public DiffTextView(Context context) { + + super(context); + } + + public DiffTextView(Context context, AttributeSet attrs) { + + super(context, attrs); + } + + public DiffTextView(Context context, AttributeSet attrs, int defStyleAttr) { + + super(context, attrs, defStyleAttr); + } + + @Override + public void setBackgroundColor(int color) { + + currentBackgroundColor = color; + super.setBackgroundColor(color); + } + + public void setInitialBackgroundColor(int initialBackgroundColor) { + + setBackgroundColor(initialBackgroundColor); + this.initialBackgroundColor = initialBackgroundColor; + } + + public int getInitialBackgroundColor() { + + return initialBackgroundColor; + } + + public int getCurrentBackgroundColor() { + + return currentBackgroundColor; + } + + public long getPosition() { + + return position; + } + + public void setPosition(int position) { + + this.position = position; + } + +} diff --git a/app/src/main/res/layout/activity_add_collaborator_to_repository.xml b/app/src/main/res/layout/activity_add_collaborator_to_repository.xml index d55cc514..e412026a 100644 --- a/app/src/main/res/layout/activity_add_collaborator_to_repository.xml +++ b/app/src/main/res/layout/activity_add_collaborator_to_repository.xml @@ -21,8 +21,8 @@ - @@ -66,9 +65,10 @@ + android:visibility="visible" /> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_file_view.xml b/app/src/main/res/layout/activity_file_view.xml index c9b681de..35510106 100644 --- a/app/src/main/res/layout/activity_file_view.xml +++ b/app/src/main/res/layout/activity_file_view.xml @@ -22,8 +22,8 @@ - - + android:layout_height="match_parent" + android:background="?attr/primaryBackgroundColor" + android:orientation="vertical" + android:paddingLeft="15dp" + android:paddingTop="7dp" + android:paddingRight="15dp" + android:paddingBottom="7dp"> - - - + + android:gravity="center_vertical" + android:orientation="horizontal"> + + + + + + + + + + - + - - - + android:layout_height="1dp" + android:background="?attr/dividerColor" /> + + + + + + + + + + + + + diff --git a/app/src/main/res/values-v23/themes.xml b/app/src/main/res/values-v23/themes.xml index 1396159a..c49d09bc 100644 --- a/app/src/main/res/values-v23/themes.xml +++ b/app/src/main/res/values-v23/themes.xml @@ -8,6 +8,9 @@ @color/colorAccent @color/lightThemeTextColor + @color/lightThemeDiffAddedColor + @color/lightThemeDiffRemovedColor + @color/lightThemeDiffSelectedColor @color/lightThemeTextColor @color/lightThemeBackground @color/lightThemeInputBackground diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index f3894629..a4320824 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -1,5 +1,8 @@ + + + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index afe65604..5bd6a624 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -26,11 +26,15 @@ #b6bbbf #368f73 #63fdd9 - #ffe0e0 - #d6fcd6 + #574343 + #485A4B + #434343 #1d1d1d #efd34a + #FCEDED + #EAF8ED + #e0e0e0 #646565 #f9f9f9 #b6bbbf diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index b231db6d..57e3530b 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -6,6 +6,7 @@ 5dp 16dp + 26dp 15dp 8dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 1ec58c8f..1496de18 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -121,6 +121,9 @@ Something went wrong, please try again Organization already exists + Binary files are not supported yet. + This file exceeds the maximum possible diff lines. + Processing Search Work in progress diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml index 500f7b5a..7712dcbc 100644 --- a/app/src/main/res/values/themes.xml +++ b/app/src/main/res/values/themes.xml @@ -8,6 +8,9 @@ @color/colorAccent @color/colorWhite + @color/diffAddedColor + @color/diffRemovedColor + @color/diffSelectedColor @color/colorWhite @color/colorPrimary @color/inputBackground @@ -31,6 +34,9 @@ @color/colorAccent @color/lightThemeTextColor + @color/lightThemeDiffAddedColor + @color/lightThemeDiffRemovedColor + @color/lightThemeDiffSelectedColor @color/lightThemeTextColor @color/lightThemeBackground @color/lightThemeInputBackground