88
app/src/main/java/org/mian/gitnex/helpers/AlertDialogs.java
Normal file
88
app/src/main/java/org/mian/gitnex/helpers/AlertDialogs.java
Normal file
@@ -0,0 +1,88 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.CreateLabelActivity;
|
||||
import org.mian.gitnex.activities.LoginActivity;
|
||||
import org.mian.gitnex.actions.CollaboratorActions;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class AlertDialogs {
|
||||
|
||||
public static void authorizationTokenRevokedDialog(final Context context, String title, String message, String copyNegativeButton, String copyPositiveButton) {
|
||||
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context, R.style.confirmDialog);
|
||||
|
||||
alertDialogBuilder
|
||||
.setTitle(title)
|
||||
.setMessage(message)
|
||||
.setCancelable(true)
|
||||
.setIcon(R.drawable.ic_warning)
|
||||
.setNegativeButton(copyNegativeButton, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.setPositiveButton(copyPositiveButton, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putBoolean("loggedInMode", false);
|
||||
tinyDb.remove("basicAuthPassword");
|
||||
tinyDb.putBoolean("basicAuthFlag", false);
|
||||
Intent intent = new Intent(context, LoginActivity.class);
|
||||
context.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
|
||||
}
|
||||
});
|
||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
public static void labelDeleteDialog(final Context context, final String labelTitle, final String labelId, String title, String message, String positiveButton, String negativeButton) {
|
||||
|
||||
new AlertDialog.Builder(context, R.style.confirmDialog)
|
||||
.setTitle(title + labelTitle)
|
||||
.setMessage(message)
|
||||
.setIcon(R.drawable.ic_delete)
|
||||
.setPositiveButton(positiveButton, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
|
||||
Intent intent = new Intent(context, CreateLabelActivity.class);
|
||||
intent.putExtra("labelId", labelId);
|
||||
intent.putExtra("labelAction", "delete");
|
||||
context.startActivity(intent);
|
||||
|
||||
}})
|
||||
.setNegativeButton(negativeButton, null).show();
|
||||
|
||||
}
|
||||
|
||||
public static void collaboratorRemoveDialog(final Context context, final String userNameMain, String title, String message, String positiveButton, String negativeButton, final String searchKeyword) {
|
||||
|
||||
new AlertDialog.Builder(context, R.style.confirmDialog)
|
||||
.setTitle(title + userNameMain)
|
||||
.setMessage(message)
|
||||
.setIcon(R.drawable.ic_warning)
|
||||
.setPositiveButton(positiveButton, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
|
||||
CollaboratorActions.deleteCollaborator(context, searchKeyword, userNameMain);
|
||||
|
||||
}})
|
||||
.setNegativeButton(negativeButton, null).show();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
42
app/src/main/java/org/mian/gitnex/helpers/Authorization.java
Normal file
42
app/src/main/java/org/mian/gitnex/helpers/Authorization.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import org.mian.gitnex.util.TinyDB;
|
||||
import okhttp3.Credentials;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class Authorization {
|
||||
|
||||
public static String returnAuthentication(Context context, String loginUid, String token) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
|
||||
String credential;
|
||||
|
||||
if(tinyDb.getBoolean("basicAuthFlag")) {
|
||||
|
||||
if (!tinyDb.getString("basicAuthPassword").isEmpty()) {
|
||||
|
||||
credential = Credentials.basic(loginUid, tinyDb.getString("basicAuthPassword"));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
credential = token;
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
credential = token;
|
||||
|
||||
}
|
||||
|
||||
return credential;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
43
app/src/main/java/org/mian/gitnex/helpers/ClickListener.java
Normal file
43
app/src/main/java/org/mian/gitnex/helpers/ClickListener.java
Normal file
@@ -0,0 +1,43 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import org.mian.gitnex.R;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class ClickListener implements View.OnClickListener {
|
||||
|
||||
private String infoText;
|
||||
private Context mCtx;
|
||||
|
||||
public ClickListener(String infoText, Context mCtx) {
|
||||
this.infoText = infoText;
|
||||
this.mCtx = mCtx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
|
||||
LayoutInflater inflater1 = LayoutInflater.from(mCtx);
|
||||
View layout = inflater1.inflate(R.layout.custom_toast,
|
||||
(ViewGroup) v.findViewById(R.id.custom_toast_container));
|
||||
|
||||
TextView text = layout.findViewById(R.id.toastText);
|
||||
text.setText(infoText);
|
||||
|
||||
Toast toast = new Toast(mCtx.getApplicationContext());
|
||||
toast.setDuration(Toast.LENGTH_LONG);
|
||||
toast.setView(layout);
|
||||
toast.show();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
27
app/src/main/java/org/mian/gitnex/helpers/ColorInverter.java
Normal file
27
app/src/main/java/org/mian/gitnex/helpers/ColorInverter.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.graphics.Color;
|
||||
import androidx.annotation.ColorInt;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class ColorInverter {
|
||||
|
||||
@ColorInt
|
||||
public int getContrastColor(@ColorInt int color) {
|
||||
|
||||
double a = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
|
||||
|
||||
int d;
|
||||
if (a < 0.5) {
|
||||
d = 0; // black
|
||||
} else {
|
||||
d = 255; // white
|
||||
}
|
||||
|
||||
return Color.rgb(d, d, d);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class LabelWidthCalculator {
|
||||
|
||||
public static int customWidth(int labelLength) {
|
||||
|
||||
int width = 33;
|
||||
|
||||
if(labelLength == 20) {
|
||||
width = ((width * labelLength) - 150);
|
||||
}
|
||||
else if(labelLength == 19) {
|
||||
width = ((width * labelLength) - 140);
|
||||
}
|
||||
else if(labelLength == 18) {
|
||||
width = ((width * labelLength) - 130);
|
||||
}
|
||||
else if(labelLength == 17) {
|
||||
width = ((width * labelLength) - 120);
|
||||
}
|
||||
else if(labelLength == 16) {
|
||||
width = ((width * labelLength) - 110);
|
||||
}
|
||||
else if(labelLength == 15) {
|
||||
width = ((width * labelLength) - 100);
|
||||
}
|
||||
else if(labelLength == 14) {
|
||||
width = ((width * labelLength) - 90);
|
||||
}
|
||||
else if(labelLength == 13) {
|
||||
width = ((width * labelLength) - 80);
|
||||
}
|
||||
else if(labelLength == 12) {
|
||||
width = ((width * labelLength) - 70);
|
||||
}
|
||||
else if(labelLength == 11) {
|
||||
width = ((width * labelLength) - 60);
|
||||
}
|
||||
else if(labelLength == 10) {
|
||||
width = ((width * labelLength) - 50);
|
||||
}
|
||||
else if(labelLength == 9) {
|
||||
width = ((width * labelLength) - 40);
|
||||
}
|
||||
else if(labelLength == 8) {
|
||||
width = ((width * labelLength) - 30);
|
||||
}
|
||||
else if(labelLength == 7) {
|
||||
width = ((width * labelLength) - 20);
|
||||
}
|
||||
else if(labelLength == 6) {
|
||||
width = ((width * labelLength) - 10);
|
||||
}
|
||||
else if(labelLength == 5) {
|
||||
width = ((width * labelLength) - 10);
|
||||
}
|
||||
else if(labelLength == 4) {
|
||||
width = ((width * labelLength) - 10);
|
||||
}
|
||||
else if(labelLength == 3) {
|
||||
width = ((width * labelLength) - 10);
|
||||
}
|
||||
else if(labelLength == 2) {
|
||||
width = ((width * labelLength));
|
||||
}
|
||||
else {
|
||||
width = (width * labelLength - 5);
|
||||
}
|
||||
|
||||
return width;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
317
app/src/main/java/org/mian/gitnex/helpers/MultiSelectDialog.java
Normal file
317
app/src/main/java/org/mian/gitnex/helpers/MultiSelectDialog.java
Normal file
@@ -0,0 +1,317 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.os.Bundle;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.adapters.MutliSelectAdapter;
|
||||
import org.mian.gitnex.models.MultiSelectModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Objects;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatDialogFragment;
|
||||
import androidx.appcompat.widget.SearchView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
|
||||
/**
|
||||
* Author com.github.abumoallim, modified by M M Arif
|
||||
*/
|
||||
|
||||
public class MultiSelectDialog extends AppCompatDialogFragment implements SearchView.OnQueryTextListener, View.OnClickListener {
|
||||
|
||||
public static ArrayList<Integer> selectedIdsForCallback = new ArrayList<>();
|
||||
|
||||
public ArrayList<MultiSelectModel> mainListOfAdapter = new ArrayList<>();
|
||||
private MutliSelectAdapter mutliSelectAdapter;
|
||||
//Default Values
|
||||
private String title;
|
||||
private float titleSize = 25;
|
||||
private String positiveText = "DONE";
|
||||
private String negativeText = "CANCEL";
|
||||
private TextView dialogTitle, dialogSubmit, dialogCancel;
|
||||
private ArrayList<Integer> previouslySelectedIdsList = new ArrayList<>();
|
||||
|
||||
private ArrayList<Integer> tempPreviouslySelectedIdsList = new ArrayList<>();
|
||||
private ArrayList<MultiSelectModel> tempMainListOfAdapter = new ArrayList<>();
|
||||
|
||||
private SubmitCallbackListener submitCallbackListener;
|
||||
|
||||
private int minSelectionLimit = 1;
|
||||
private String minSelectionMessage = null;
|
||||
private int maxSelectionLimit = 0;
|
||||
private String maxSelectionMessage = null;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
|
||||
final Dialog dialog = new Dialog(Objects.requireNonNull(getActivity()));
|
||||
Objects.requireNonNull(dialog.getWindow()).requestFeature(Window.FEATURE_NO_TITLE);
|
||||
dialog.getWindow().setFlags(
|
||||
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
|
||||
dialog.setContentView(R.layout.custom_multi_select);
|
||||
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
|
||||
RecyclerViewEmptySupport mrecyclerView = dialog.findViewById(R.id.recycler_view);
|
||||
SearchView searchView = dialog.findViewById(R.id.search_view);
|
||||
dialogTitle = dialog.findViewById(R.id.title);
|
||||
dialogSubmit = dialog.findViewById(R.id.done);
|
||||
dialogCancel = dialog.findViewById(R.id.cancel);
|
||||
|
||||
mrecyclerView.setEmptyView(dialog.findViewById(R.id.list_empty1));
|
||||
@SuppressLint("WrongConstant") LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
|
||||
mrecyclerView.setLayoutManager(layoutManager);
|
||||
|
||||
dialogSubmit.setOnClickListener(this);
|
||||
dialogCancel.setOnClickListener(this);
|
||||
|
||||
settingValues();
|
||||
|
||||
mainListOfAdapter = setCheckedIDS(mainListOfAdapter, previouslySelectedIdsList);
|
||||
mutliSelectAdapter = new MutliSelectAdapter(mainListOfAdapter, getContext());
|
||||
mrecyclerView.setAdapter(mutliSelectAdapter);
|
||||
|
||||
searchView.setOnQueryTextListener(this);
|
||||
searchView.onActionViewExpanded();
|
||||
searchView.clearFocus();
|
||||
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
public MultiSelectDialog title(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog titleSize(float titleSize) {
|
||||
this.titleSize = titleSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog positiveText(@NonNull String message) {
|
||||
this.positiveText = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog negativeText(@NonNull String message) {
|
||||
this.negativeText = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog preSelectIDsList(ArrayList<Integer> list) {
|
||||
this.previouslySelectedIdsList = list;
|
||||
this.tempPreviouslySelectedIdsList = new ArrayList<>(previouslySelectedIdsList);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog multiSelectList(ArrayList<MultiSelectModel> list) {
|
||||
this.mainListOfAdapter = list;
|
||||
this.tempMainListOfAdapter = new ArrayList<>(mainListOfAdapter);
|
||||
if(maxSelectionLimit == 0)
|
||||
maxSelectionLimit = list.size();
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog setMaxSelectionLimit(int limit){
|
||||
this.maxSelectionLimit = limit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog setMaxSelectionMessage(String message) {
|
||||
this.maxSelectionMessage = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog setMinSelectionLimit(int limit){
|
||||
this.minSelectionLimit = limit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog setMinSelectionMessage(String message) {
|
||||
this.minSelectionMessage = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MultiSelectDialog onSubmit(@NonNull SubmitCallbackListener callback) {
|
||||
this.submitCallbackListener = callback;
|
||||
return this;
|
||||
}
|
||||
|
||||
private void settingValues() {
|
||||
dialogTitle.setText(title);
|
||||
dialogTitle.setTextSize(TypedValue.COMPLEX_UNIT_SP, titleSize);
|
||||
dialogSubmit.setText(positiveText.toUpperCase());
|
||||
dialogCancel.setText(negativeText.toUpperCase());
|
||||
}
|
||||
|
||||
private ArrayList<MultiSelectModel> setCheckedIDS(ArrayList<MultiSelectModel> multiselectdata, ArrayList<Integer> listOfIdsSelected) {
|
||||
|
||||
for (int i = 0; i < multiselectdata.size(); i++) {
|
||||
multiselectdata.get(i).setSelected(false);
|
||||
for (int j = 0; j < listOfIdsSelected.size(); j++) {
|
||||
if (listOfIdsSelected.get(j) == (multiselectdata.get(i).getId())) {
|
||||
multiselectdata.get(i).setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return multiselectdata;
|
||||
|
||||
}
|
||||
|
||||
private ArrayList<MultiSelectModel> filter(ArrayList<MultiSelectModel> models, String query) {
|
||||
|
||||
query = query.toLowerCase();
|
||||
final ArrayList<MultiSelectModel> filteredModelList = new ArrayList<>();
|
||||
if (query.equals("") | query.isEmpty()) {
|
||||
filteredModelList.addAll(models);
|
||||
return filteredModelList;
|
||||
}
|
||||
|
||||
for (MultiSelectModel model : models) {
|
||||
final String name = model.getName().toLowerCase();
|
||||
if (name.contains(query)) {
|
||||
filteredModelList.add(model);
|
||||
}
|
||||
}
|
||||
return filteredModelList;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
|
||||
selectedIdsForCallback = previouslySelectedIdsList;
|
||||
mainListOfAdapter = setCheckedIDS(mainListOfAdapter, selectedIdsForCallback);
|
||||
ArrayList<MultiSelectModel> filteredlist = filter(mainListOfAdapter, newText);
|
||||
mutliSelectAdapter.setData(filteredlist, newText.toLowerCase(), mutliSelectAdapter);
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
if (view.getId() == R.id.done) {
|
||||
ArrayList<Integer> callBackListOfIds = selectedIdsForCallback;
|
||||
|
||||
if (callBackListOfIds.size() >= minSelectionLimit) {
|
||||
if (callBackListOfIds.size() <= maxSelectionLimit) {
|
||||
|
||||
//to remember last selected ids which were successfully done
|
||||
tempPreviouslySelectedIdsList = new ArrayList<>(callBackListOfIds);
|
||||
|
||||
if(submitCallbackListener !=null) {
|
||||
submitCallbackListener.onSelected(callBackListOfIds, getSelectNameList(), getSelectedDataString());
|
||||
}
|
||||
dismiss();
|
||||
} else {
|
||||
String youCan = getResources().getString(R.string.you_can_only_select_upto);
|
||||
String options = getResources().getString(R.string.options);
|
||||
String option = getResources().getString(R.string.option);
|
||||
String message = "";
|
||||
|
||||
if(this.maxSelectionMessage != null) {
|
||||
message = maxSelectionMessage;
|
||||
}
|
||||
else {
|
||||
if (maxSelectionLimit > 1)
|
||||
message = youCan + " " + maxSelectionLimit + " " + options;
|
||||
else
|
||||
message = youCan + " " + maxSelectionLimit + " " + option;
|
||||
}
|
||||
Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
String pleaseSelect = getResources().getString(R.string.please_select_atleast);
|
||||
String options = getResources().getString(R.string.options);
|
||||
String option = getResources().getString(R.string.option);
|
||||
String message = "";
|
||||
|
||||
if(this.minSelectionMessage != null) {
|
||||
message = minSelectionMessage;
|
||||
}
|
||||
else {
|
||||
if (minSelectionLimit > 1)
|
||||
message = pleaseSelect + " " + minSelectionLimit + " " + options;
|
||||
else
|
||||
message = pleaseSelect + " " + minSelectionLimit + " " + option;
|
||||
}
|
||||
Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
if (view.getId() == R.id.cancel) {
|
||||
if(submitCallbackListener!=null){
|
||||
selectedIdsForCallback.clear();
|
||||
selectedIdsForCallback.addAll(tempPreviouslySelectedIdsList);
|
||||
submitCallbackListener.onCancel();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private String getSelectedDataString() {
|
||||
|
||||
String data = "";
|
||||
for (int i = 0; i < tempMainListOfAdapter.size(); i++) {
|
||||
if (checkForSelection(tempMainListOfAdapter.get(i).getId())) {
|
||||
data = data + ", " + tempMainListOfAdapter.get(i).getName();
|
||||
}
|
||||
}
|
||||
if (data.length() > 0) {
|
||||
return data.substring(1);
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ArrayList<String> getSelectNameList() {
|
||||
|
||||
ArrayList<String> names = new ArrayList<>();
|
||||
for(int i=0;i<tempMainListOfAdapter.size();i++){
|
||||
if(checkForSelection(tempMainListOfAdapter.get(i).getId())){
|
||||
names.add(tempMainListOfAdapter.get(i).getName());
|
||||
}
|
||||
}
|
||||
return names;
|
||||
|
||||
}
|
||||
|
||||
private boolean checkForSelection(Integer id) {
|
||||
|
||||
for (int i = 0; i < MultiSelectDialog.selectedIdsForCallback.size(); i++) {
|
||||
if (id.equals(MultiSelectDialog.selectedIdsForCallback.get(i))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/* public void setCallbackListener(SubmitCallbackListener submitCallbackListener) {
|
||||
this.submitCallbackListener = submitCallbackListener;
|
||||
}*/
|
||||
|
||||
public interface SubmitCallbackListener {
|
||||
void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String commonSeperatedData);
|
||||
void onCancel();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
/**
|
||||
* Author com.github.abumoallim, modified by M M Arif
|
||||
*/
|
||||
|
||||
public class RecyclerViewEmptySupport extends RecyclerView {
|
||||
|
||||
private View emptyView;
|
||||
|
||||
final private AdapterDataObserver observer = new AdapterDataObserver() {
|
||||
|
||||
@Override
|
||||
public void onChanged() {
|
||||
checkIfEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeInserted(int positionStart, int itemCount) {
|
||||
checkIfEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemRangeRemoved(int positionStart, int itemCount) {
|
||||
checkIfEmpty();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
public RecyclerViewEmptySupport(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public RecyclerViewEmptySupport(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public RecyclerViewEmptySupport(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
}
|
||||
|
||||
void checkIfEmpty() {
|
||||
|
||||
if (emptyView != null && getAdapter() != null) {
|
||||
final boolean emptyViewVisible = getAdapter().getItemCount() == 0;
|
||||
emptyView.setVisibility(emptyViewVisible ? VISIBLE : GONE);
|
||||
setVisibility(emptyViewVisible ? GONE : VISIBLE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAdapter(Adapter adapter) {
|
||||
|
||||
final Adapter oldAdapter = getAdapter();
|
||||
if (oldAdapter != null) {
|
||||
oldAdapter.unregisterAdapterDataObserver(observer);
|
||||
}
|
||||
super.setAdapter(adapter);
|
||||
if (adapter != null) {
|
||||
adapter.registerAdapterDataObserver(observer);
|
||||
}
|
||||
|
||||
checkIfEmpty();
|
||||
|
||||
}
|
||||
|
||||
public void setEmptyView(View emptyView) {
|
||||
this.emptyView = emptyView;
|
||||
checkIfEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class RoundedTransformation implements com.squareup.picasso.Transformation {
|
||||
private final int radius;
|
||||
private final int margin; // dp
|
||||
|
||||
// radius is corner radius in dp
|
||||
// margin is the board in dp
|
||||
public RoundedTransformation(final int radius, final int margin) {
|
||||
this.radius = radius;
|
||||
this.margin = margin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bitmap transform(final Bitmap source) {
|
||||
final Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP,
|
||||
Shader.TileMode.CLAMP));
|
||||
|
||||
Bitmap output = Bitmap.createBitmap(source.getWidth(),
|
||||
source.getHeight(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
canvas.drawRoundRect(new RectF(margin, margin, source.getWidth()
|
||||
- margin, source.getHeight() - margin), radius, radius, paint);
|
||||
|
||||
if (source != output) {
|
||||
source.recycle();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String key() {
|
||||
return "rounded";
|
||||
}
|
||||
}
|
||||
35
app/src/main/java/org/mian/gitnex/helpers/TimeHelper.java
Normal file
35
app/src/main/java/org/mian/gitnex/helpers/TimeHelper.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
|
||||
public class TimeHelper {
|
||||
|
||||
public static String customDateFormatForToast(String customDate) {
|
||||
|
||||
String[] parts = customDate.split("\\+");
|
||||
String part1 = parts[0] + "Z";
|
||||
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.ENGLISH);
|
||||
Date createdTime = null;
|
||||
try {
|
||||
createdTime = formatter.parse(part1);
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
DateFormat format = DateFormat.getDateTimeInstance();
|
||||
return format.format(createdTime);
|
||||
|
||||
}
|
||||
|
||||
public static String customDateFormatForToastDateFormat(Date customDate) {
|
||||
|
||||
DateFormat format = DateFormat.getDateTimeInstance();
|
||||
return format.format(customDate);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
31
app/src/main/java/org/mian/gitnex/helpers/Toasty.java
Normal file
31
app/src/main/java/org/mian/gitnex/helpers/Toasty.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import org.mian.gitnex.R;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class Toasty {
|
||||
|
||||
public static void info(Context context, String message) {
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
View view = inflater.inflate( context.getResources().getLayout(R.layout.custom_toast), null );
|
||||
|
||||
TextView text = view.findViewById(R.id.toastText);
|
||||
text.setText(message);
|
||||
|
||||
Toast toast = new Toast(context);
|
||||
toast.setDuration(Toast.LENGTH_LONG);
|
||||
toast.setView(view);
|
||||
toast.show();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
42
app/src/main/java/org/mian/gitnex/helpers/UrlHelper.java
Normal file
42
app/src/main/java/org/mian/gitnex/helpers/UrlHelper.java
Normal file
@@ -0,0 +1,42 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class UrlHelper {
|
||||
|
||||
public static String cleanUrl(String url) {
|
||||
|
||||
URI uri = null;
|
||||
try {
|
||||
uri = new URI(url);
|
||||
} catch (URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
assert uri != null;
|
||||
String urlProtocol = uri.getScheme();
|
||||
String urlHost = uri.getHost();
|
||||
int urlPort = uri.getPort();
|
||||
|
||||
String urlFinal = null;
|
||||
if(urlPort > 0) {
|
||||
urlFinal = urlProtocol + "://" + urlHost + ":" + urlPort;
|
||||
}
|
||||
else if(urlProtocol != null) {
|
||||
urlFinal = urlProtocol + "://" + urlHost;
|
||||
}
|
||||
else {
|
||||
urlFinal = urlHost;
|
||||
}
|
||||
|
||||
return urlFinal;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
35
app/src/main/java/org/mian/gitnex/helpers/UserMentions.java
Normal file
35
app/src/main/java/org/mian/gitnex/helpers/UserMentions.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package org.mian.gitnex.helpers;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import org.mian.gitnex.R;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class UserMentions {
|
||||
|
||||
public static Spannable UserMentionsFunc(Context mCtx, CharSequence bodyWithMD, String currentItemBody) {
|
||||
|
||||
Spannable bodyWithMentions = new SpannableString(bodyWithMD);
|
||||
Pattern pattern = Pattern.compile("@\\w+");
|
||||
Matcher matcher = pattern.matcher(bodyWithMD);
|
||||
|
||||
while (matcher.find())
|
||||
{
|
||||
|
||||
int indexStart = String.valueOf(bodyWithMD).indexOf(matcher.group());
|
||||
int indexEnd = indexStart + matcher.group().length();
|
||||
bodyWithMentions.setSpan(new ForegroundColorSpan(mCtx.getResources().getColor(R.color.colorDarkGreen)), indexStart, indexEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
|
||||
}
|
||||
return bodyWithMentions;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user