mirror of
https://codeberg.org/gitnex/GitNex.git
synced 2023-12-13 20:50:18 +01:00
Fix format
This commit is contained in:
parent
ca3a41e068
commit
f238686d9d
|
@ -12,19 +12,18 @@ import android.view.View;
|
|||
import android.view.inputmethod.InputMethodManager;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.database.api.BaseApi;
|
||||
import org.mian.gitnex.database.api.NotesApi;
|
||||
import org.mian.gitnex.database.models.Notes;
|
||||
import org.mian.gitnex.databinding.ActivityCreateNoteBinding;
|
||||
import org.mian.gitnex.helpers.Markdown;
|
||||
import java.time.Instant;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class CreateNoteActivity extends BaseActivity {
|
||||
|
||||
private ActivityCreateNoteBinding activityCreateNoteBinding;
|
||||
|
@ -45,86 +44,91 @@ public class CreateNoteActivity extends BaseActivity {
|
|||
setContentView(activityCreateNoteBinding.getRoot());
|
||||
setSupportActionBar(activityCreateNoteBinding.toolbar);
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
InputMethodManager imm =
|
||||
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
assert imm != null;
|
||||
imm.showSoftInput(activityCreateNoteBinding.noteContent, InputMethodManager.SHOW_IMPLICIT);
|
||||
activityCreateNoteBinding.noteContent.requestFocus();
|
||||
|
||||
activityCreateNoteBinding.close.setOnClickListener(view -> finish());
|
||||
|
||||
if(getIntent().getStringExtra("action") != null) {
|
||||
if (getIntent().getStringExtra("action") != null) {
|
||||
action = getIntent().getStringExtra("action");
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
action = "";
|
||||
}
|
||||
|
||||
activityCreateNoteBinding.close.setOnClickListener(close -> finish());
|
||||
activityCreateNoteBinding.toolbarTitle.setMovementMethod(new ScrollingMovementMethod());
|
||||
|
||||
if(action.equalsIgnoreCase("edit")) {
|
||||
if (action.equalsIgnoreCase("edit")) {
|
||||
|
||||
noteId = getIntent().getIntExtra( "noteId", 0);
|
||||
noteId = getIntent().getIntExtra("noteId", 0);
|
||||
notes = notesApi.fetchNoteById(noteId);
|
||||
activityCreateNoteBinding.noteContent.setText(notes.getContent());
|
||||
|
||||
activityCreateNoteBinding.markdownPreview.setVisibility(View.GONE);
|
||||
activityCreateNoteBinding.toolbarTitle.setText(R.string.editNote);
|
||||
|
||||
activityCreateNoteBinding.noteContent.addTextChangedListener(new TextWatcher() {
|
||||
activityCreateNoteBinding.noteContent.addTextChangedListener(
|
||||
new TextWatcher() {
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
String text = activityCreateNoteBinding.noteContent.getText().toString();
|
||||
String text =
|
||||
activityCreateNoteBinding.noteContent.getText().toString();
|
||||
|
||||
if(!text.isEmpty()) {
|
||||
if (!text.isEmpty()) {
|
||||
|
||||
updateNote(text);
|
||||
}
|
||||
}
|
||||
updateNote(text);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
@Override
|
||||
public void beforeTextChanged(
|
||||
CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
});
|
||||
}
|
||||
else if(action.equalsIgnoreCase("add")) {
|
||||
@Override
|
||||
public void onTextChanged(
|
||||
CharSequence s, int start, int before, int count) {}
|
||||
});
|
||||
} else if (action.equalsIgnoreCase("add")) {
|
||||
|
||||
activityCreateNoteBinding.markdownPreview.setVisibility(View.GONE);
|
||||
|
||||
activityCreateNoteBinding.noteContent.addTextChangedListener(new TextWatcher() {
|
||||
activityCreateNoteBinding.noteContent.addTextChangedListener(
|
||||
new TextWatcher() {
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
String text = activityCreateNoteBinding.noteContent.getText().toString();
|
||||
String text =
|
||||
activityCreateNoteBinding.noteContent.getText().toString();
|
||||
|
||||
if(!text.isEmpty() && text.length() > 4) {
|
||||
if (!text.isEmpty() && text.length() > 4) {
|
||||
|
||||
if(noteId > 0) {
|
||||
updateNote(text);
|
||||
if (noteId > 0) {
|
||||
updateNote(text);
|
||||
} else {
|
||||
noteId =
|
||||
(int)
|
||||
notesApi.insertNote(
|
||||
text,
|
||||
(int) Instant.now().getEpochSecond());
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
noteId = (int) notesApi.insertNote(text, (int) Instant.now().getEpochSecond());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
@Override
|
||||
public void beforeTextChanged(
|
||||
CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
@Override
|
||||
public void onTextChanged(
|
||||
CharSequence s, int start, int before, int count) {}
|
||||
});
|
||||
} else {
|
||||
activityCreateNoteBinding.markdownPreview.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
@ -147,22 +151,28 @@ public class CreateNoteActivity extends BaseActivity {
|
|||
|
||||
int id = item.getItemId();
|
||||
|
||||
if(id == android.R.id.home) {
|
||||
if (id == android.R.id.home) {
|
||||
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
else if(id == R.id.markdown) {
|
||||
} else if (id == R.id.markdown) {
|
||||
|
||||
if(action.equalsIgnoreCase("edit") || action.equalsIgnoreCase("add")) {
|
||||
if(!renderMd) {
|
||||
Markdown.render(ctx, EmojiParser.parseToUnicode(Objects.requireNonNull(activityCreateNoteBinding.noteContent.getText().toString())), activityCreateNoteBinding.markdownPreview);
|
||||
if (action.equalsIgnoreCase("edit") || action.equalsIgnoreCase("add")) {
|
||||
if (!renderMd) {
|
||||
Markdown.render(
|
||||
ctx,
|
||||
EmojiParser.parseToUnicode(
|
||||
Objects.requireNonNull(
|
||||
activityCreateNoteBinding
|
||||
.noteContent
|
||||
.getText()
|
||||
.toString())),
|
||||
activityCreateNoteBinding.markdownPreview);
|
||||
|
||||
activityCreateNoteBinding.markdownPreview.setVisibility(View.VISIBLE);
|
||||
activityCreateNoteBinding.noteContent.setVisibility(View.GONE);
|
||||
renderMd = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
activityCreateNoteBinding.markdownPreview.setVisibility(View.GONE);
|
||||
activityCreateNoteBinding.noteContent.setVisibility(View.VISIBLE);
|
||||
renderMd = false;
|
||||
|
@ -170,8 +180,7 @@ public class CreateNoteActivity extends BaseActivity {
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -945,9 +945,12 @@ public class IssueDetailActivity extends BaseActivity
|
|||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", locale);
|
||||
String dueDate = formatter.format(issue.getIssue().getDueDate());
|
||||
viewBinding.issueDueDate.setText(dueDate);
|
||||
viewBinding.issueDueDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issue.getIssue().getDueDate()), ctx));
|
||||
}
|
||||
else {
|
||||
viewBinding.issueDueDate.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(
|
||||
issue.getIssue().getDueDate()),
|
||||
ctx));
|
||||
} else {
|
||||
|
||||
viewBinding.dueDateFrame.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -970,8 +973,13 @@ public class IssueDetailActivity extends BaseActivity
|
|||
}
|
||||
|
||||
viewBinding.issueCreatedTime.setVisibility(View.VISIBLE);
|
||||
viewBinding.issueCreatedTime.setText(TimeHelper.formatTime(issue.getIssue().getCreatedAt(), locale));
|
||||
viewBinding.issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issue.getIssue().getCreatedAt()), ctx));
|
||||
viewBinding.issueCreatedTime.setText(
|
||||
TimeHelper.formatTime(issue.getIssue().getCreatedAt(), locale));
|
||||
viewBinding.issueCreatedTime.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(
|
||||
issue.getIssue().getCreatedAt()),
|
||||
ctx));
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("repoOwner", repoOwner);
|
||||
|
|
|
@ -144,11 +144,9 @@ public class MainActivity extends BaseActivity
|
|||
toolbarTitle.setText(getResources().getString(R.string.navProfile));
|
||||
} else if (fragmentById instanceof MostVisitedReposFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.navMostVisited));
|
||||
}
|
||||
else if(fragmentById instanceof NotesFragment) {
|
||||
} else if (fragmentById instanceof NotesFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.navNotes));
|
||||
}
|
||||
else if(fragmentById instanceof DraftsFragment) {
|
||||
} else if (fragmentById instanceof DraftsFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
|
||||
} else if (fragmentById instanceof AdministrationFragment) {
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleAdministration));
|
||||
|
@ -497,7 +495,10 @@ public class MainActivity extends BaseActivity
|
|||
break;
|
||||
case 10:
|
||||
toolbarTitle.setText(getResources().getString(R.string.navNotes));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotesFragment()).commit();
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, new NotesFragment())
|
||||
.commit();
|
||||
navigationView.setCheckedItem(R.id.nav_notes);
|
||||
break;
|
||||
|
||||
|
@ -718,11 +719,13 @@ public class MainActivity extends BaseActivity
|
|||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, new MostVisitedReposFragment())
|
||||
.commit();
|
||||
}
|
||||
else if(id == R.id.nav_notes) {
|
||||
} else if (id == R.id.nav_notes) {
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.navNotes));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotesFragment()).commit();
|
||||
getSupportFragmentManager()
|
||||
.beginTransaction()
|
||||
.replace(R.id.fragment_container, new NotesFragment())
|
||||
.commit();
|
||||
}
|
||||
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
|
@ -877,10 +880,9 @@ public class MainActivity extends BaseActivity
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<User> call, @NonNull Throwable t) {
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<User> call, @NonNull Throwable t) {}
|
||||
});
|
||||
}
|
||||
|
||||
private void getNotificationsCount() {
|
||||
|
|
|
@ -22,7 +22,6 @@ import org.mian.gitnex.helpers.Toasty;
|
|||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class SettingsAppearanceActivity extends BaseActivity {
|
||||
|
||||
private static String[] customFontList;
|
||||
|
@ -36,14 +35,16 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
|||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
ActivitySettingsAppearanceBinding activitySettingsAppearanceBinding = ActivitySettingsAppearanceBinding.inflate(getLayoutInflater());
|
||||
ActivitySettingsAppearanceBinding activitySettingsAppearanceBinding =
|
||||
ActivitySettingsAppearanceBinding.inflate(getLayoutInflater());
|
||||
setContentView(activitySettingsAppearanceBinding.getRoot());
|
||||
|
||||
ImageView closeActivity = activitySettingsAppearanceBinding.close;
|
||||
|
||||
LinearLayout customFontFrame = activitySettingsAppearanceBinding.customFontFrame;
|
||||
LinearLayout themeFrame = activitySettingsAppearanceBinding.themeSelectionFrame;
|
||||
LinearLayout lightTimeFrame = activitySettingsAppearanceBinding.lightThemeTimeSelectionFrame;
|
||||
LinearLayout lightTimeFrame =
|
||||
activitySettingsAppearanceBinding.lightThemeTimeSelectionFrame;
|
||||
LinearLayout darkTimeFrame = activitySettingsAppearanceBinding.darkThemeTimeSelectionFrame;
|
||||
|
||||
SwitchMaterial counterBadgesSwitch = activitySettingsAppearanceBinding.switchCounterBadge;
|
||||
|
@ -56,35 +57,39 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
|||
|
||||
String lightMinute = String.valueOf(tinyDB.getInt("lightThemeTimeMinute"));
|
||||
String lightHour = String.valueOf(tinyDB.getInt("lightThemeTimeHour"));
|
||||
if(lightMinute.length() == 1) {
|
||||
if (lightMinute.length() == 1) {
|
||||
lightMinute = "0" + lightMinute;
|
||||
}
|
||||
if(lightHour.length() == 1) {
|
||||
if (lightHour.length() == 1) {
|
||||
lightHour = "0" + lightHour;
|
||||
}
|
||||
|
||||
String darkMinute = String.valueOf(tinyDB.getInt("darkThemeTimeMinute"));
|
||||
String darkHour = String.valueOf(tinyDB.getInt("darkThemeTimeHour"));
|
||||
if(darkMinute.length() == 1) {
|
||||
if (darkMinute.length() == 1) {
|
||||
darkMinute = "0" + darkMinute;
|
||||
}
|
||||
if(darkHour.length() == 1) {
|
||||
if (darkHour.length() == 1) {
|
||||
darkHour = "0" + darkHour;
|
||||
}
|
||||
|
||||
customFontSelectedChoice = tinyDB.getInt("customFontId", 1);
|
||||
themeSelectedChoice = tinyDB.getInt("themeId", 6); // use system theme as default
|
||||
|
||||
activitySettingsAppearanceBinding.lightThemeSelectedTime.setText(ctx.getResources().getString(R.string.settingsThemeTimeSelectedHint, lightHour, lightMinute));
|
||||
activitySettingsAppearanceBinding.darkThemeSelectedTime.setText(ctx.getResources().getString(R.string.settingsThemeTimeSelectedHint, darkHour, darkMinute));
|
||||
activitySettingsAppearanceBinding.customFontSelected.setText(customFontList[customFontSelectedChoice]);
|
||||
activitySettingsAppearanceBinding.lightThemeSelectedTime.setText(
|
||||
ctx.getResources()
|
||||
.getString(R.string.settingsThemeTimeSelectedHint, lightHour, lightMinute));
|
||||
activitySettingsAppearanceBinding.darkThemeSelectedTime.setText(
|
||||
ctx.getResources()
|
||||
.getString(R.string.settingsThemeTimeSelectedHint, darkHour, darkMinute));
|
||||
activitySettingsAppearanceBinding.customFontSelected.setText(
|
||||
customFontList[customFontSelectedChoice]);
|
||||
activitySettingsAppearanceBinding.themeSelected.setText(themeList[themeSelectedChoice]);
|
||||
|
||||
if(themeList[themeSelectedChoice].startsWith("Auto")) {
|
||||
if (themeList[themeSelectedChoice].startsWith("Auto")) {
|
||||
darkTimeFrame.setVisibility(View.VISIBLE);
|
||||
lightTimeFrame.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
darkTimeFrame.setVisibility(View.GONE);
|
||||
lightTimeFrame.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -92,87 +97,111 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
|||
counterBadgesSwitch.setChecked(tinyDB.getBoolean("enableCounterBadges", true));
|
||||
|
||||
// counter badge switcher
|
||||
counterBadgesSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
tinyDB.putBoolean("enableCounterBadges", isChecked);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
activitySettingsAppearanceBinding.counterBadgeFrame.setOnClickListener(v -> counterBadgesSwitch.setChecked(!counterBadgesSwitch.isChecked()));
|
||||
|
||||
// show labels in lists(issues, pr) - default is color dots
|
||||
activitySettingsAppearanceBinding.switchLabelsInListBadge.setChecked(tinyDB.getBoolean("showLabelsInList", false));
|
||||
|
||||
activitySettingsAppearanceBinding.switchLabelsInListBadge.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
tinyDB.putBoolean("showLabelsInList", isChecked);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
activitySettingsAppearanceBinding.labelsInListFrame.setOnClickListener(
|
||||
v -> activitySettingsAppearanceBinding.switchLabelsInListBadge.setChecked(!activitySettingsAppearanceBinding.switchLabelsInListBadge.isChecked()));
|
||||
|
||||
// theme selection dialog
|
||||
themeFrame.setOnClickListener(view -> {
|
||||
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(ctx).setTitle(R.string.themeSelectorDialogTitle)
|
||||
.setSingleChoiceItems(themeList, themeSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||
|
||||
themeSelectedChoice = i;
|
||||
activitySettingsAppearanceBinding.themeSelected.setText(themeList[i]);
|
||||
tinyDB.putInt("themeId", i);
|
||||
|
||||
SettingsFragment.refreshParent = true;
|
||||
this.recreate();
|
||||
this.overridePendingTransition(0, 0);
|
||||
dialogInterfaceTheme.dismiss();
|
||||
counterBadgesSwitch.setOnCheckedChangeListener(
|
||||
(buttonView, isChecked) -> {
|
||||
tinyDB.putBoolean("enableCounterBadges", isChecked);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
activitySettingsAppearanceBinding.counterBadgeFrame.setOnClickListener(
|
||||
v -> counterBadgesSwitch.setChecked(!counterBadgesSwitch.isChecked()));
|
||||
|
||||
materialAlertDialogBuilder.create().show();
|
||||
});
|
||||
// show labels in lists(issues, pr) - default is color dots
|
||||
activitySettingsAppearanceBinding.switchLabelsInListBadge.setChecked(
|
||||
tinyDB.getBoolean("showLabelsInList", false));
|
||||
|
||||
lightTimeFrame.setOnClickListener(view -> {
|
||||
LightTimePicker timePicker = new LightTimePicker();
|
||||
timePicker.show(getSupportFragmentManager(), "timePicker");
|
||||
});
|
||||
activitySettingsAppearanceBinding.switchLabelsInListBadge.setOnCheckedChangeListener(
|
||||
(buttonView, isChecked) -> {
|
||||
tinyDB.putBoolean("showLabelsInList", isChecked);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
activitySettingsAppearanceBinding.labelsInListFrame.setOnClickListener(
|
||||
v ->
|
||||
activitySettingsAppearanceBinding.switchLabelsInListBadge.setChecked(
|
||||
!activitySettingsAppearanceBinding.switchLabelsInListBadge
|
||||
.isChecked()));
|
||||
|
||||
darkTimeFrame.setOnClickListener(view -> {
|
||||
DarkTimePicker timePicker = new DarkTimePicker();
|
||||
timePicker.show(getSupportFragmentManager(), "timePicker");
|
||||
});
|
||||
// theme selection dialog
|
||||
themeFrame.setOnClickListener(
|
||||
view -> {
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder =
|
||||
new MaterialAlertDialogBuilder(ctx)
|
||||
.setTitle(R.string.themeSelectorDialogTitle)
|
||||
.setSingleChoiceItems(
|
||||
themeList,
|
||||
themeSelectedChoice,
|
||||
(dialogInterfaceTheme, i) -> {
|
||||
themeSelectedChoice = i;
|
||||
activitySettingsAppearanceBinding.themeSelected
|
||||
.setText(themeList[i]);
|
||||
tinyDB.putInt("themeId", i);
|
||||
|
||||
// custom font dialog
|
||||
customFontFrame.setOnClickListener(view -> {
|
||||
SettingsFragment.refreshParent = true;
|
||||
this.recreate();
|
||||
this.overridePendingTransition(0, 0);
|
||||
dialogInterfaceTheme.dismiss();
|
||||
Toasty.success(
|
||||
appCtx,
|
||||
getResources()
|
||||
.getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(ctx).setTitle(R.string.settingsCustomFontSelectorDialogTitle).setCancelable(customFontSelectedChoice != -1)
|
||||
.setSingleChoiceItems(customFontList, customFontSelectedChoice, (dialogInterfaceCustomFont, i) -> {
|
||||
|
||||
customFontSelectedChoice = i;
|
||||
activitySettingsAppearanceBinding.customFontSelected.setText(customFontList[i]);
|
||||
tinyDB.putInt("customFontId", i);
|
||||
AppUtil.typeface = null; // reset typeface
|
||||
FontsOverride.setDefaultFont(this);
|
||||
|
||||
SettingsFragment.refreshParent = true;
|
||||
this.recreate();
|
||||
this.overridePendingTransition(0, 0);
|
||||
dialogInterfaceCustomFont.dismiss();
|
||||
Toasty.success(appCtx, appCtx.getResources().getString(R.string.settingsSave));
|
||||
materialAlertDialogBuilder.create().show();
|
||||
});
|
||||
|
||||
materialAlertDialogBuilder.create().show();
|
||||
});
|
||||
lightTimeFrame.setOnClickListener(
|
||||
view -> {
|
||||
LightTimePicker timePicker = new LightTimePicker();
|
||||
timePicker.show(getSupportFragmentManager(), "timePicker");
|
||||
});
|
||||
|
||||
darkTimeFrame.setOnClickListener(
|
||||
view -> {
|
||||
DarkTimePicker timePicker = new DarkTimePicker();
|
||||
timePicker.show(getSupportFragmentManager(), "timePicker");
|
||||
});
|
||||
|
||||
// custom font dialog
|
||||
customFontFrame.setOnClickListener(
|
||||
view -> {
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder =
|
||||
new MaterialAlertDialogBuilder(ctx)
|
||||
.setTitle(R.string.settingsCustomFontSelectorDialogTitle)
|
||||
.setCancelable(customFontSelectedChoice != -1)
|
||||
.setSingleChoiceItems(
|
||||
customFontList,
|
||||
customFontSelectedChoice,
|
||||
(dialogInterfaceCustomFont, i) -> {
|
||||
customFontSelectedChoice = i;
|
||||
activitySettingsAppearanceBinding.customFontSelected
|
||||
.setText(customFontList[i]);
|
||||
tinyDB.putInt("customFontId", i);
|
||||
AppUtil.typeface = null; // reset typeface
|
||||
FontsOverride.setDefaultFont(this);
|
||||
|
||||
SettingsFragment.refreshParent = true;
|
||||
this.recreate();
|
||||
this.overridePendingTransition(0, 0);
|
||||
dialogInterfaceCustomFont.dismiss();
|
||||
Toasty.success(
|
||||
appCtx,
|
||||
appCtx.getResources()
|
||||
.getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
materialAlertDialogBuilder.create().show();
|
||||
});
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
onClickListener = view -> finish();
|
||||
}
|
||||
|
||||
public static class LightTimePicker extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
|
||||
public static class LightTimePicker extends DialogFragment
|
||||
implements TimePickerDialog.OnTimeSetListener {
|
||||
|
||||
TinyDB db = TinyDB.getInstance(getContext());
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
int hour = db.getInt("lightThemeTimeHour");
|
||||
int minute = db.getInt("lightThemeTimeMinute");
|
||||
|
@ -187,18 +216,19 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
|||
SettingsFragment.refreshParent = true;
|
||||
requireActivity().overridePendingTransition(0, 0);
|
||||
this.dismiss();
|
||||
Toasty.success(requireActivity().getApplicationContext(), requireContext().getResources().getString(R.string.settingsSave));
|
||||
Toasty.success(
|
||||
requireActivity().getApplicationContext(),
|
||||
requireContext().getResources().getString(R.string.settingsSave));
|
||||
requireActivity().recreate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class DarkTimePicker extends DialogFragment implements TimePickerDialog.OnTimeSetListener {
|
||||
public static class DarkTimePicker extends DialogFragment
|
||||
implements TimePickerDialog.OnTimeSetListener {
|
||||
|
||||
TinyDB db = TinyDB.getInstance(getContext());
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
int hour = db.getInt("darkThemeTimeHour");
|
||||
int minute = db.getInt("darkThemeTimeMinute");
|
||||
|
@ -213,10 +243,10 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
|||
SettingsFragment.refreshParent = true;
|
||||
requireActivity().overridePendingTransition(0, 0);
|
||||
this.dismiss();
|
||||
Toasty.success(requireActivity().getApplicationContext(), requireContext().getResources().getString(R.string.settingsSave));
|
||||
Toasty.success(
|
||||
requireActivity().getApplicationContext(),
|
||||
requireContext().getResources().getString(R.string.settingsSave));
|
||||
requireActivity().recreate();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -90,8 +90,7 @@ public class SettingsGeneralActivity extends BaseActivity {
|
|||
|
||||
viewBinding.homeScreenSelected.setText(
|
||||
getResources().getString(R.string.navMostVisited));
|
||||
}
|
||||
else if(homeScreenSelectedChoice == 10) {
|
||||
} else if (homeScreenSelectedChoice == 10) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.navNotes));
|
||||
}
|
||||
|
|
|
@ -53,12 +53,12 @@ public class AdminCronTasksAdapter
|
|||
String nextRun = "";
|
||||
String lastRun = "";
|
||||
|
||||
if(cronTasks.getNext() != null) {
|
||||
nextRun = TimeHelper.formatTime(cronTasks.getNext(), locale);
|
||||
}
|
||||
if(cronTasks.getPrev() != null) {
|
||||
lastRun = TimeHelper.formatTime(cronTasks.getPrev(), locale);
|
||||
}
|
||||
if (cronTasks.getNext() != null) {
|
||||
nextRun = TimeHelper.formatTime(cronTasks.getNext(), locale);
|
||||
}
|
||||
if (cronTasks.getPrev() != null) {
|
||||
lastRun = TimeHelper.formatTime(cronTasks.getPrev(), locale);
|
||||
}
|
||||
|
||||
View view =
|
||||
LayoutInflater.from(ctx)
|
||||
|
@ -120,7 +120,8 @@ public class AdminCronTasksAdapter
|
|||
|
||||
Call<Void> call = RetrofitClient.getApiInterface(ctx).adminCronRun(taskName);
|
||||
|
||||
call.enqueue(new Callback<>() {
|
||||
call.enqueue(
|
||||
new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(
|
||||
|
|
|
@ -136,6 +136,7 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
|
||||
public interface OnLoadMoreListener {
|
||||
void onLoadMore();
|
||||
|
||||
void onLoadFinished();
|
||||
}
|
||||
|
||||
|
|
|
@ -126,16 +126,37 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||
|
||||
commitSubject.setText(EmojiParser.parseToUnicode(commitMessageParts[0].trim()));
|
||||
|
||||
if(!Objects.equals(commitsModel.getCommit().getCommitter().getEmail(), commitsModel.getCommit().getAuthor().getEmail())) {
|
||||
commitAuthorAndCommitter.setText(HtmlCompat.fromHtml(
|
||||
context.getString(R.string.commitAuthoredByAndCommittedByWhen, commitsModel.getCommit().getAuthor().getName(), commitsModel.getCommit().getCommitter().getName(),
|
||||
TimeHelper.formatTime(TimeHelper.parseIso8601(commitsModel.getCommit().getCommitter().getDate()), context.getResources().getConfiguration().locale)),
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
}
|
||||
else {
|
||||
commitAuthorAndCommitter.setText(HtmlCompat.fromHtml(context.getString(R.string.commitCommittedByWhen, commitsModel.getCommit().getCommitter().getName(),
|
||||
TimeHelper.formatTime(TimeHelper.parseIso8601(commitsModel.getCommit().getCommitter().getDate()), context.getResources().getConfiguration().locale)),
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
if (!Objects.equals(
|
||||
commitsModel.getCommit().getCommitter().getEmail(),
|
||||
commitsModel.getCommit().getAuthor().getEmail())) {
|
||||
commitAuthorAndCommitter.setText(
|
||||
HtmlCompat.fromHtml(
|
||||
context.getString(
|
||||
R.string.commitAuthoredByAndCommittedByWhen,
|
||||
commitsModel.getCommit().getAuthor().getName(),
|
||||
commitsModel.getCommit().getCommitter().getName(),
|
||||
TimeHelper.formatTime(
|
||||
TimeHelper.parseIso8601(
|
||||
commitsModel
|
||||
.getCommit()
|
||||
.getCommitter()
|
||||
.getDate()),
|
||||
context.getResources().getConfiguration().locale)),
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
} else {
|
||||
commitAuthorAndCommitter.setText(
|
||||
HtmlCompat.fromHtml(
|
||||
context.getString(
|
||||
R.string.commitCommittedByWhen,
|
||||
commitsModel.getCommit().getCommitter().getName(),
|
||||
TimeHelper.formatTime(
|
||||
TimeHelper.parseIso8601(
|
||||
commitsModel
|
||||
.getCommit()
|
||||
.getCommitter()
|
||||
.getDate()),
|
||||
context.getResources().getConfiguration().locale)),
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
}
|
||||
|
||||
if (commitsModel.getAuthor() != null
|
||||
|
@ -146,10 +167,15 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||
|
||||
int imgRadius = AppUtil.getPixelsFromDensity(context, 60);
|
||||
|
||||
PicassoService.getInstance(context).get().load(commitsModel.getAuthor().getAvatarUrl()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120)
|
||||
.centerCrop().into(commitAuthorAvatar);
|
||||
}
|
||||
else {
|
||||
PicassoService.getInstance(context)
|
||||
.get()
|
||||
.load(commitsModel.getAuthor().getAvatarUrl())
|
||||
.placeholder(R.drawable.loader_animated)
|
||||
.transform(new RoundedTransformation(imgRadius, 0))
|
||||
.resize(120, 120)
|
||||
.centerCrop()
|
||||
.into(commitAuthorAvatar);
|
||||
} else {
|
||||
commitAuthorAvatar.setImageDrawable(null);
|
||||
commitAuthorAvatarFrame.setVisibility(View.GONE);
|
||||
}
|
||||
|
@ -167,10 +193,15 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
|||
|
||||
int imgRadius = AppUtil.getPixelsFromDensity(context, 60);
|
||||
|
||||
PicassoService.getInstance(context).get().load(commitsModel.getCommitter().getAvatarUrl()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120)
|
||||
.centerCrop().into(commitCommitterAvatar);
|
||||
}
|
||||
else {
|
||||
PicassoService.getInstance(context)
|
||||
.get()
|
||||
.load(commitsModel.getCommitter().getAvatarUrl())
|
||||
.placeholder(R.drawable.loader_animated)
|
||||
.transform(new RoundedTransformation(imgRadius, 0))
|
||||
.resize(120, 120)
|
||||
.centerCrop()
|
||||
.into(commitCommitterAvatar);
|
||||
} else {
|
||||
commitCommitterAvatar.setImageDrawable(null);
|
||||
commitCommitterAvatarFrame.setVisibility(View.GONE);
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ import androidx.core.content.res.ResourcesCompat;
|
|||
import androidx.core.text.HtmlCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.gitnex.tea4j.v2.models.Issue;
|
||||
|
@ -38,8 +36,6 @@ import org.mian.gitnex.helpers.TimeHelper;
|
|||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.contexts.IssueContext;
|
||||
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
|
@ -320,7 +316,10 @@ public class ExploreIssuesAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
}
|
||||
|
||||
issueCreatedTime.setText(TimeHelper.formatTime(issue.getCreatedAt(), locale));
|
||||
issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issue.getCreatedAt()), context));
|
||||
issueCreatedTime.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(issue.getCreatedAt()),
|
||||
context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.mian.gitnex.R;
|
||||
|
@ -27,8 +25,6 @@ import org.mian.gitnex.helpers.RoundedTransformation;
|
|||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
|
@ -172,11 +168,17 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<RecyclerVie
|
|||
image.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
if(userRepositories.getUpdatedAt() != null) {
|
||||
repoLastUpdated.setText(context.getString(R.string.lastUpdatedAt, TimeHelper.formatTime(userRepositories.getUpdatedAt(), locale)));
|
||||
repoLastUpdated.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(userRepositories.getUpdatedAt()), context));
|
||||
}
|
||||
else {
|
||||
if (userRepositories.getUpdatedAt() != null) {
|
||||
repoLastUpdated.setText(
|
||||
context.getString(
|
||||
R.string.lastUpdatedAt,
|
||||
TimeHelper.formatTime(userRepositories.getUpdatedAt(), locale)));
|
||||
repoLastUpdated.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(
|
||||
userRepositories.getUpdatedAt()),
|
||||
context));
|
||||
} else {
|
||||
repoLastUpdated.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
|
|
@ -469,12 +469,20 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<RecyclerView.View
|
|||
StringBuilder infoBuilder = null;
|
||||
if (issueComment.getCreatedAt() != null) {
|
||||
|
||||
infoBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreatedAt(), locale));
|
||||
infoBuilder =
|
||||
new StringBuilder(
|
||||
TimeHelper.formatTime(issueComment.getCreatedAt(), locale));
|
||||
|
||||
information.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issueComment.getCreatedAt()), context));
|
||||
information.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(
|
||||
issueComment.getCreatedAt()),
|
||||
context));
|
||||
|
||||
if(!issueComment.getCreatedAt().equals(issueComment.getUpdatedAt())) {
|
||||
infoBuilder.append(context.getString(R.string.colorfulBulletSpan)).append(context.getString(R.string.modifiedText));
|
||||
if (!issueComment.getCreatedAt().equals(issueComment.getUpdatedAt())) {
|
||||
infoBuilder
|
||||
.append(context.getString(R.string.colorfulBulletSpan))
|
||||
.append(context.getString(R.string.modifiedText));
|
||||
}
|
||||
}
|
||||
String info = infoBuilder.toString();
|
||||
|
|
|
@ -21,8 +21,6 @@ import androidx.core.text.HtmlCompat;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.gitnex.tea4j.v2.models.Issue;
|
||||
|
@ -39,8 +37,6 @@ import org.mian.gitnex.helpers.RoundedTransformation;
|
|||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.contexts.IssueContext;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
|
@ -295,7 +291,10 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
|||
}
|
||||
|
||||
this.issueCreatedTime.setText(TimeHelper.formatTime(issue.getCreatedAt(), locale));
|
||||
this.issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(issue.getCreatedAt()), context));
|
||||
this.issueCreatedTime.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(issue.getCreatedAt()),
|
||||
context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -252,14 +252,18 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||
assert date != null;
|
||||
String dueDate = formatter.format(date);
|
||||
|
||||
if(date.before(new Date())) {
|
||||
msDueDate.setTextColor(ResourcesCompat.getColor(context.getResources(), R.color.darkRed, null));
|
||||
if (date.before(new Date())) {
|
||||
msDueDate.setTextColor(
|
||||
ResourcesCompat.getColor(
|
||||
context.getResources(), R.color.darkRed, null));
|
||||
}
|
||||
|
||||
msDueDate.setText(dueDate);
|
||||
msDueDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(dataModel.getDueOn()), context));
|
||||
}
|
||||
else {
|
||||
msDueDate.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(dataModel.getDueOn()),
|
||||
context));
|
||||
} else {
|
||||
|
||||
msDueDate.setText(context.getString(R.string.milestoneNoDueDate));
|
||||
}
|
||||
|
|
|
@ -12,6 +12,11 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.CreateNoteActivity;
|
||||
|
@ -21,16 +26,10 @@ import org.mian.gitnex.database.models.Notes;
|
|||
import org.mian.gitnex.helpers.Markdown;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import java.time.Instant;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class NotesAdapter extends RecyclerView.Adapter<NotesAdapter.NotesViewHolder> {
|
||||
|
||||
private List<Notes> notesList;
|
||||
|
@ -58,20 +57,31 @@ public class NotesAdapter extends RecyclerView.Adapter<NotesAdapter.NotesViewHol
|
|||
datetime = itemView.findViewById(R.id.datetime);
|
||||
ImageView deleteNote = itemView.findViewById(R.id.delete_note);
|
||||
|
||||
itemView.setOnClickListener(view -> {
|
||||
noteIntent.putExtra("action", "edit");
|
||||
noteIntent.putExtra("noteId", notes.getNoteId());
|
||||
ctx.startActivity(noteIntent);
|
||||
});
|
||||
itemView.setOnClickListener(
|
||||
view -> {
|
||||
noteIntent.putExtra("action", "edit");
|
||||
noteIntent.putExtra("noteId", notes.getNoteId());
|
||||
ctx.startActivity(noteIntent);
|
||||
});
|
||||
|
||||
deleteNote.setOnClickListener(itemDelete -> {
|
||||
deleteNote.setOnClickListener(
|
||||
itemDelete -> {
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder =
|
||||
new MaterialAlertDialogBuilder(
|
||||
ctx, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
||||
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(ctx, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
||||
|
||||
materialAlertDialogBuilder.setTitle(ctx.getString(R.string.menuDeleteText))
|
||||
.setMessage(ctx.getString(R.string.noteDeleteDialoMessage))
|
||||
.setPositiveButton(R.string.menuDeleteText, (dialog, whichButton) -> deleteNote(getBindingAdapterPosition(), notes.getNoteId())).setNeutralButton(R.string.cancelButton, null).show();
|
||||
});
|
||||
materialAlertDialogBuilder
|
||||
.setTitle(ctx.getString(R.string.menuDeleteText))
|
||||
.setMessage(ctx.getString(R.string.noteDeleteDialoMessage))
|
||||
.setPositiveButton(
|
||||
R.string.menuDeleteText,
|
||||
(dialog, whichButton) ->
|
||||
deleteNote(
|
||||
getBindingAdapterPosition(),
|
||||
notes.getNoteId()))
|
||||
.setNeutralButton(R.string.cancelButton, null)
|
||||
.show();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,10 +96,12 @@ public class NotesAdapter extends RecyclerView.Adapter<NotesAdapter.NotesViewHol
|
|||
Toasty.success(ctx, ctx.getResources().getQuantityString(R.plurals.noteDeleteMessage, 1));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public NotesAdapter.NotesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_notes, parent, false);
|
||||
@NonNull @Override
|
||||
public NotesAdapter.NotesViewHolder onCreateViewHolder(
|
||||
@NonNull ViewGroup parent, int viewType) {
|
||||
View v =
|
||||
LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_notes, parent, false);
|
||||
return new NotesViewHolder(v);
|
||||
}
|
||||
|
||||
|
@ -100,15 +112,25 @@ public class NotesAdapter extends RecyclerView.Adapter<NotesAdapter.NotesViewHol
|
|||
Notes currentItem = notesList.get(position);
|
||||
holder.notes = currentItem;
|
||||
|
||||
Markdown.render(ctx, EmojiParser.parseToUnicode(Objects.requireNonNull(StringUtils.substring(currentItem.getContent(), 0, 140))), holder.content);
|
||||
Markdown.render(
|
||||
ctx,
|
||||
EmojiParser.parseToUnicode(
|
||||
Objects.requireNonNull(
|
||||
StringUtils.substring(currentItem.getContent(), 0, 140))),
|
||||
holder.content);
|
||||
|
||||
if(currentItem.getModified() != null) {
|
||||
String modifiedTime = TimeHelper.formatTime(Date.from(Instant.ofEpochSecond(currentItem.getModified())), locale);
|
||||
holder.datetime.setText(ctx.getResources().getString(R.string.noteTimeModified, modifiedTime));
|
||||
}
|
||||
else {
|
||||
String createdTime = TimeHelper.formatTime(Date.from(Instant.ofEpochSecond(currentItem.getDatetime())), locale);
|
||||
holder.datetime.setText(ctx.getResources().getString(R.string.noteDateTime, createdTime));
|
||||
if (currentItem.getModified() != null) {
|
||||
String modifiedTime =
|
||||
TimeHelper.formatTime(
|
||||
Date.from(Instant.ofEpochSecond(currentItem.getModified())), locale);
|
||||
holder.datetime.setText(
|
||||
ctx.getResources().getString(R.string.noteTimeModified, modifiedTime));
|
||||
} else {
|
||||
String createdTime =
|
||||
TimeHelper.formatTime(
|
||||
Date.from(Instant.ofEpochSecond(currentItem.getDatetime())), locale);
|
||||
holder.datetime.setText(
|
||||
ctx.getResources().getString(R.string.noteDateTime, createdTime));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -296,7 +296,11 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
|||
context.getResources().getColor(R.color.releasePre, null));
|
||||
}
|
||||
|
||||
this.prCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(pullRequest.getCreatedAt()), context));
|
||||
this.prCreatedTime.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(
|
||||
pullRequest.getCreatedAt()),
|
||||
context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.gitnex.tea4j.v2.models.Release;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
|
@ -30,8 +32,6 @@ import org.mian.gitnex.helpers.RoundedTransformation;
|
|||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.structs.FragmentRefreshListener;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
@ -39,7 +39,6 @@ import retrofit2.Response;
|
|||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.ReleasesViewHolder> {
|
||||
|
||||
private final Context context;
|
||||
|
@ -51,7 +50,13 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
|||
private OnLoadMoreListener loadMoreListener;
|
||||
private boolean isLoading = false, isMoreDataAvailable = true;
|
||||
|
||||
public ReleasesAdapter(Context ctx, List<Release> releasesMain, FragmentRefreshListener startDownload, String repoOwner, String repoName, FragmentReleasesBinding fragmentReleasesBinding) {
|
||||
public ReleasesAdapter(
|
||||
Context ctx,
|
||||
List<Release> releasesMain,
|
||||
FragmentRefreshListener startDownload,
|
||||
String repoOwner,
|
||||
String repoName,
|
||||
FragmentReleasesBinding fragmentReleasesBinding) {
|
||||
this.context = ctx;
|
||||
this.releasesList = releasesMain;
|
||||
this.startDownload = startDownload;
|
||||
|
@ -60,10 +65,12 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
|||
this.fragmentReleasesBinding = fragmentReleasesBinding;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ReleasesAdapter.ReleasesViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_releases, parent, false);
|
||||
@NonNull @Override
|
||||
public ReleasesAdapter.ReleasesViewHolder onCreateViewHolder(
|
||||
@NonNull ViewGroup parent, int viewType) {
|
||||
View v =
|
||||
LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_releases, parent, false);
|
||||
return new ReleasesAdapter.ReleasesViewHolder(v);
|
||||
}
|
||||
|
||||
|
@ -78,70 +85,83 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
|||
|
||||
holder.releaseName.setText(currentItem.getName());
|
||||
|
||||
if(currentItem.isPrerelease()) {
|
||||
if (currentItem.isPrerelease()) {
|
||||
holder.releaseType.setBackgroundResource(R.drawable.shape_pre_release);
|
||||
holder.releaseType.setText(R.string.releaseTypePre);
|
||||
}
|
||||
else if(currentItem.isDraft()) {
|
||||
} else if (currentItem.isDraft()) {
|
||||
holder.releaseType.setBackgroundResource(R.drawable.shape_draft_release);
|
||||
holder.releaseType.setText(R.string.releaseDraftText);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
holder.releaseType.setBackgroundResource(R.drawable.shape_stable_release);
|
||||
holder.releaseType.setText(R.string.releaseTypeStable);
|
||||
}
|
||||
|
||||
if(currentItem.getAuthor().getAvatarUrl() != null) {
|
||||
PicassoService.getInstance(context).get().load(currentItem.getAuthor().getAvatarUrl()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop()
|
||||
.into(holder.authorAvatar);
|
||||
if (currentItem.getAuthor().getAvatarUrl() != null) {
|
||||
PicassoService.getInstance(context)
|
||||
.get()
|
||||
.load(currentItem.getAuthor().getAvatarUrl())
|
||||
.placeholder(R.drawable.loader_animated)
|
||||
.transform(new RoundedTransformation(imgRadius, 0))
|
||||
.resize(120, 120)
|
||||
.centerCrop()
|
||||
.into(holder.authorAvatar);
|
||||
}
|
||||
|
||||
holder.authorName.setText(context.getResources().getString(R.string.releasePublishedBy, currentItem.getAuthor().getLogin()));
|
||||
holder.authorName.setText(
|
||||
context.getResources()
|
||||
.getString(
|
||||
R.string.releasePublishedBy, currentItem.getAuthor().getLogin()));
|
||||
|
||||
if(currentItem.getTagName() != null) {
|
||||
if (currentItem.getTagName() != null) {
|
||||
holder.releaseTag.setText(currentItem.getTagName());
|
||||
}
|
||||
|
||||
if(currentItem.getPublishedAt() != null) {
|
||||
if (currentItem.getPublishedAt() != null) {
|
||||
holder.releaseDate.setText(TimeHelper.formatTime(currentItem.getPublishedAt(), locale));
|
||||
}
|
||||
|
||||
holder.releaseDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getPublishedAt()), context));
|
||||
holder.releaseDate.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(currentItem.getPublishedAt()),
|
||||
context));
|
||||
|
||||
if(!currentItem.getBody().equals("")) {
|
||||
if (!currentItem.getBody().equals("")) {
|
||||
Markdown.render(context, currentItem.getBody(), holder.releaseBodyContent);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
holder.releaseBodyContent.setText(R.string.noReleaseBodyContent);
|
||||
}
|
||||
|
||||
holder.downloadCopyFrame.setOnClickListener(v -> {
|
||||
holder.downloadCopyFrame.setOnClickListener(
|
||||
v -> {
|
||||
if (holder.downloads.getVisibility() == View.GONE) {
|
||||
|
||||
if(holder.downloads.getVisibility() == View.GONE) {
|
||||
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_chevron_down);
|
||||
holder.downloads.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
|
||||
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_chevron_down);
|
||||
holder.downloads.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_chevron_right);
|
||||
holder.downloads.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_chevron_right);
|
||||
holder.downloads.setVisibility(View.GONE);
|
||||
}
|
||||
holder.releaseZipDownloadFrame.setOnClickListener(
|
||||
v -> startDownload.onRefresh(currentItem.getZipballUrl()));
|
||||
holder.releaseTarDownloadFrame.setOnClickListener(
|
||||
v -> startDownload.onRefresh(currentItem.getTarballUrl()));
|
||||
|
||||
});
|
||||
|
||||
holder.releaseZipDownloadFrame.setOnClickListener(v -> startDownload.onRefresh(currentItem.getZipballUrl()));
|
||||
holder.releaseTarDownloadFrame.setOnClickListener(v -> startDownload.onRefresh(currentItem.getTarballUrl()));
|
||||
|
||||
ReleasesDownloadsAdapter adapter = new ReleasesDownloadsAdapter(currentItem.getAssets(), startDownload);
|
||||
ReleasesDownloadsAdapter adapter =
|
||||
new ReleasesDownloadsAdapter(currentItem.getAssets(), startDownload);
|
||||
holder.downloadList.setAdapter(adapter);
|
||||
|
||||
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
||||
if (position >= getItemCount() - 1
|
||||
&& isMoreDataAvailable
|
||||
&& !isLoading
|
||||
&& loadMoreListener != null) {
|
||||
isLoading = true;
|
||||
loadMoreListener.onLoadMore();
|
||||
}
|
||||
|
||||
if(!((RepoDetailActivity) context).repository.getPermissions().isPush()) {
|
||||
if (!((RepoDetailActivity) context).repository.getPermissions().isPush()) {
|
||||
holder.optionsMenu.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
@ -153,7 +173,7 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
|||
|
||||
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||
isMoreDataAvailable = moreDataAvailable;
|
||||
if(!isMoreDataAvailable) {
|
||||
if (!isMoreDataAvailable) {
|
||||
loadMoreListener.onLoadFinished();
|
||||
}
|
||||
}
|
||||
|
@ -180,38 +200,76 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
|||
notifyItemRangeChanged(position, releasesList.size());
|
||||
}
|
||||
|
||||
private void deleteRelease(final Context context, final String releaseName, final Long releaseId, final String owner, final String repo, int position) {
|
||||
private void deleteRelease(
|
||||
final Context context,
|
||||
final String releaseName,
|
||||
final Long releaseId,
|
||||
final String owner,
|
||||
final String repo,
|
||||
int position) {
|
||||
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder =
|
||||
new MaterialAlertDialogBuilder(
|
||||
context, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
||||
|
||||
materialAlertDialogBuilder.setTitle(String.format(context.getString(R.string.deleteGenericTitle), releaseName)).setMessage(R.string.deleteReleaseConfirmation)
|
||||
.setPositiveButton(R.string.menuDeleteText, (dialog, whichButton) -> RetrofitClient.getApiInterface(context).repoDeleteRelease(owner, repo, releaseId).enqueue(new Callback<>() {
|
||||
materialAlertDialogBuilder
|
||||
.setTitle(
|
||||
String.format(context.getString(R.string.deleteGenericTitle), releaseName))
|
||||
.setMessage(R.string.deleteReleaseConfirmation)
|
||||
.setPositiveButton(
|
||||
R.string.menuDeleteText,
|
||||
(dialog, whichButton) ->
|
||||
RetrofitClient.getApiInterface(context)
|
||||
.repoDeleteRelease(owner, repo, releaseId)
|
||||
.enqueue(
|
||||
new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<Void> call, @NonNull Response<Void> response) {
|
||||
@Override
|
||||
public void onResponse(
|
||||
@NonNull Call<Void> call,
|
||||
@NonNull Response<Void> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
updateAdapter(position);
|
||||
Toasty.success(context, context.getString(R.string.releaseDeleted));
|
||||
MainActivity.reloadRepos = true;
|
||||
if(getItemCount() == 0) {
|
||||
fragmentReleasesBinding.noDataReleases.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
Toasty.error(context, context.getString(R.string.authorizeError));
|
||||
}
|
||||
else {
|
||||
Toasty.error(context, context.getString(R.string.genericError));
|
||||
}
|
||||
}
|
||||
if (response.isSuccessful()) {
|
||||
updateAdapter(position);
|
||||
Toasty.success(
|
||||
context,
|
||||
context.getString(
|
||||
R.string
|
||||
.releaseDeleted));
|
||||
MainActivity.reloadRepos = true;
|
||||
if (getItemCount() == 0) {
|
||||
fragmentReleasesBinding
|
||||
.noDataReleases
|
||||
.setVisibility(
|
||||
View.VISIBLE);
|
||||
}
|
||||
} else if (response.code() == 403) {
|
||||
Toasty.error(
|
||||
context,
|
||||
context.getString(
|
||||
R.string
|
||||
.authorizeError));
|
||||
} else {
|
||||
Toasty.error(
|
||||
context,
|
||||
context.getString(
|
||||
R.string.genericError));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
||||
@Override
|
||||
public void onFailure(
|
||||
@NonNull Call<Void> call,
|
||||
@NonNull Throwable t) {
|
||||
|
||||
Toasty.error(context, context.getString(R.string.genericError));
|
||||
}
|
||||
})).setNeutralButton(R.string.cancelButton, null).show();
|
||||
Toasty.error(
|
||||
context,
|
||||
context.getString(
|
||||
R.string.genericError));
|
||||
}
|
||||
}))
|
||||
.setNeutralButton(R.string.cancelButton, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
public interface OnLoadMoreListener {
|
||||
|
@ -219,7 +277,6 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
|||
void onLoadMore();
|
||||
|
||||
void onLoadFinished();
|
||||
|
||||
}
|
||||
|
||||
protected class ReleasesViewHolder extends RecyclerView.ViewHolder {
|
||||
|
@ -263,37 +320,55 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
|||
downloadList.setHasFixedSize(true);
|
||||
downloadList.setLayoutManager(new LinearLayoutManager(itemView.getContext()));
|
||||
|
||||
new Handler().postDelayed(() -> {
|
||||
if(!AppUtil.checkGhostUsers(releases.getAuthor().getLogin())) {
|
||||
new Handler()
|
||||
.postDelayed(
|
||||
() -> {
|
||||
if (!AppUtil.checkGhostUsers(releases.getAuthor().getLogin())) {
|
||||
|
||||
authorAvatar.setOnClickListener(loginId -> {
|
||||
Context context = loginId.getContext();
|
||||
authorAvatar.setOnClickListener(
|
||||
loginId -> {
|
||||
Context context = loginId.getContext();
|
||||
|
||||
Intent intent = new Intent(context, ProfileActivity.class);
|
||||
intent.putExtra("username", releases.getAuthor().getLogin());
|
||||
context.startActivity(intent);
|
||||
Intent intent =
|
||||
new Intent(context, ProfileActivity.class);
|
||||
intent.putExtra(
|
||||
"username",
|
||||
releases.getAuthor().getLogin());
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
},
|
||||
500);
|
||||
|
||||
optionsMenu.setOnClickListener(
|
||||
v -> {
|
||||
final Context context = v.getContext();
|
||||
|
||||
View view =
|
||||
LayoutInflater.from(context)
|
||||
.inflate(
|
||||
R.layout.bottom_sheet_release_in_list,
|
||||
itemView.findViewById(android.R.id.content),
|
||||
false);
|
||||
|
||||
TextView deleteRelease = view.findViewById(R.id.deleteRelease);
|
||||
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
deleteRelease.setOnClickListener(
|
||||
v1 -> {
|
||||
deleteRelease(
|
||||
context,
|
||||
releases.getName(),
|
||||
releases.getId(),
|
||||
repoOwner,
|
||||
repoName,
|
||||
getBindingAdapterPosition());
|
||||
dialog.dismiss();
|
||||
});
|
||||
});
|
||||
}
|
||||
}, 500);
|
||||
|
||||
optionsMenu.setOnClickListener(v -> {
|
||||
final Context context = v.getContext();
|
||||
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_release_in_list, itemView.findViewById(android.R.id.content), false);
|
||||
|
||||
TextView deleteRelease = view.findViewById(R.id.deleteRelease);
|
||||
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(context);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
deleteRelease.setOnClickListener(v1 -> {
|
||||
deleteRelease(context, releases.getName(), releases.getId(), repoOwner, repoName, getBindingAdapterPosition());
|
||||
dialog.dismiss();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
|
@ -23,13 +25,10 @@ import org.mian.gitnex.helpers.RoundedTransformation;
|
|||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class RepoForksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private final Context context;
|
||||
|
@ -38,23 +37,27 @@ public class RepoForksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
private boolean isLoading = false;
|
||||
private boolean isMoreDataAvailable = true;
|
||||
|
||||
public RepoForksAdapter(Context ctx, List<org.gitnex.tea4j.v2.models.Repository> forksListMain) {
|
||||
public RepoForksAdapter(
|
||||
Context ctx, List<org.gitnex.tea4j.v2.models.Repository> forksListMain) {
|
||||
|
||||
this.context = ctx;
|
||||
this.forksList = forksListMain;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
return new RepoForksAdapter.ForksHolder(inflater.inflate(R.layout.list_repositories, parent, false));
|
||||
return new RepoForksAdapter.ForksHolder(
|
||||
inflater.inflate(R.layout.list_repositories, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
|
||||
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
||||
if (position >= getItemCount() - 1
|
||||
&& isMoreDataAvailable
|
||||
&& !isLoading
|
||||
&& loadMoreListener != null) {
|
||||
isLoading = true;
|
||||
loadMoreListener.run();
|
||||
}
|
||||
|
@ -129,54 +132,69 @@ public class RepoForksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
int color = generator.getColor(forksModel.getName());
|
||||
String firstCharacter = String.valueOf(forksModel.getFullName().charAt(0));
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 3);
|
||||
TextDrawable drawable =
|
||||
TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.fontSize(18)
|
||||
.toUpperCase()
|
||||
.width(28)
|
||||
.height(28)
|
||||
.endConfig()
|
||||
.buildRoundRect(firstCharacter, color, 3);
|
||||
|
||||
if(forksModel.getAvatarUrl() != null) {
|
||||
if(!forksModel.getAvatarUrl().equals("")) {
|
||||
PicassoService.getInstance(context).get().load(forksModel.getAvatarUrl()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop()
|
||||
.into(image);
|
||||
}
|
||||
else {
|
||||
if (forksModel.getAvatarUrl() != null) {
|
||||
if (!forksModel.getAvatarUrl().equals("")) {
|
||||
PicassoService.getInstance(context)
|
||||
.get()
|
||||
.load(forksModel.getAvatarUrl())
|
||||
.placeholder(R.drawable.loader_animated)
|
||||
.transform(new RoundedTransformation(imgRadius, 0))
|
||||
.resize(120, 120)
|
||||
.centerCrop()
|
||||
.into(image);
|
||||
} else {
|
||||
image.setImageDrawable(drawable);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
image.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
if(forksModel.getUpdatedAt() != null) {
|
||||
repoLastUpdated.setText(context.getString(R.string.lastUpdatedAt, TimeHelper.formatTime(forksModel.getUpdatedAt(), locale)));
|
||||
repoLastUpdated.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(forksModel.getUpdatedAt()), context));
|
||||
}
|
||||
else {
|
||||
if (forksModel.getUpdatedAt() != null) {
|
||||
repoLastUpdated.setText(
|
||||
context.getString(
|
||||
R.string.lastUpdatedAt,
|
||||
TimeHelper.formatTime(forksModel.getUpdatedAt(), locale)));
|
||||
repoLastUpdated.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(
|
||||
forksModel.getUpdatedAt()),
|
||||
context));
|
||||
} else {
|
||||
repoLastUpdated.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(!forksModel.getDescription().equals("")) {
|
||||
if (!forksModel.getDescription().equals("")) {
|
||||
repoDescription.setText(forksModel.getDescription());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
repoDescription.setText(context.getString(R.string.noDataDescription));
|
||||
}
|
||||
|
||||
if(isRepoAdmin == null) {
|
||||
if (isRepoAdmin == null) {
|
||||
isRepoAdmin = new CheckBox(context);
|
||||
}
|
||||
isRepoAdmin.setChecked(forksModel.getPermissions().isAdmin());
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
itemView.setOnClickListener(
|
||||
v -> {
|
||||
Context context = v.getContext();
|
||||
|
||||
Context context = v.getContext();
|
||||
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
||||
repo.saveToDB(context);
|
||||
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
||||
|
||||
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
||||
repo.saveToDB(context);
|
||||
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
||||
|
||||
context.startActivity(intent);
|
||||
|
||||
});
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ import androidx.annotation.NonNull;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
|
@ -25,15 +28,12 @@ import org.mian.gitnex.helpers.RoundedTransformation;
|
|||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class ReposListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements Filterable {
|
||||
public class ReposListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
implements Filterable {
|
||||
|
||||
private final Context context;
|
||||
private final List<org.gitnex.tea4j.v2.models.Repository> reposListFull;
|
||||
|
@ -42,58 +42,65 @@ public class ReposListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
private List<org.gitnex.tea4j.v2.models.Repository> reposList;
|
||||
private OnLoadMoreListener loadMoreListener;
|
||||
private boolean isLoading = false, isMoreDataAvailable = true;
|
||||
private final Filter reposFilter = new Filter() {
|
||||
private final Filter reposFilter =
|
||||
new Filter() {
|
||||
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
|
||||
List<org.gitnex.tea4j.v2.models.Repository> filteredList = new ArrayList<>();
|
||||
List<org.gitnex.tea4j.v2.models.Repository> filteredList = new ArrayList<>();
|
||||
|
||||
if(constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(reposListFull);
|
||||
}
|
||||
else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
filteredList.addAll(reposListFull);
|
||||
} else {
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for(org.gitnex.tea4j.v2.models.Repository item : reposListFull) {
|
||||
if(item.getFullName().toLowerCase().contains(filterPattern) || item.getDescription().toLowerCase().contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
for (org.gitnex.tea4j.v2.models.Repository item : reposListFull) {
|
||||
if (item.getFullName().toLowerCase().contains(filterPattern)
|
||||
|| item.getDescription()
|
||||
.toLowerCase()
|
||||
.contains(filterPattern)) {
|
||||
filteredList.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
FilterResults results = new FilterResults();
|
||||
results.values = filteredList;
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
|
||||
return results;
|
||||
}
|
||||
reposList.clear();
|
||||
reposList.addAll((List) results.values);
|
||||
notifyDataChanged();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
|
||||
reposList.clear();
|
||||
reposList.addAll((List) results.values);
|
||||
notifyDataChanged();
|
||||
}
|
||||
};
|
||||
|
||||
public ReposListAdapter(List<org.gitnex.tea4j.v2.models.Repository> reposListMain, Context ctx) {
|
||||
public ReposListAdapter(
|
||||
List<org.gitnex.tea4j.v2.models.Repository> reposListMain, Context ctx) {
|
||||
this.context = ctx;
|
||||
this.reposList = reposListMain;
|
||||
reposListFull = new ArrayList<>(reposList);
|
||||
this.tinyDb = TinyDB.getInstance(context);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
LayoutInflater inflater = LayoutInflater.from(context);
|
||||
return new ReposListAdapter.ReposHolder(inflater.inflate(R.layout.list_repositories, parent, false));
|
||||
return new ReposListAdapter.ReposHolder(
|
||||
inflater.inflate(R.layout.list_repositories, parent, false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
||||
if (position >= getItemCount() - 1
|
||||
&& isMoreDataAvailable
|
||||
&& !isLoading
|
||||
&& loadMoreListener != null) {
|
||||
isLoading = true;
|
||||
loadMoreListener.onLoadMore();
|
||||
}
|
||||
|
@ -113,7 +120,7 @@ public class ReposListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
|
||||
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||
isMoreDataAvailable = moreDataAvailable;
|
||||
if(!isMoreDataAvailable) {
|
||||
if (!isMoreDataAvailable) {
|
||||
loadMoreListener.onLoadFinished();
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +149,7 @@ public class ReposListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
public interface OnLoadMoreListener {
|
||||
|
||||
void onLoadMore();
|
||||
|
||||
void onLoadFinished();
|
||||
}
|
||||
|
||||
|
@ -169,16 +177,17 @@ public class ReposListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
repoLastUpdated = itemView.findViewById(R.id.repoLastUpdated);
|
||||
spacerView = itemView.findViewById(R.id.spacerView);
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
Context context = v.getContext();
|
||||
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
||||
repo.saveToDB(context);
|
||||
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
||||
if(isUserOrg) {
|
||||
intent.putExtra("openedFromUserOrg", true);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
});
|
||||
itemView.setOnClickListener(
|
||||
v -> {
|
||||
Context context = v.getContext();
|
||||
RepositoryContext repo = new RepositoryContext(userRepositories, context);
|
||||
repo.saveToDB(context);
|
||||
Intent intent = repo.getIntent(context, RepoDetailActivity.class);
|
||||
if (isUserOrg) {
|
||||
intent.putExtra("openedFromUserOrg", true);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
@ -196,45 +205,58 @@ public class ReposListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
int color = generator.getColor(repositories.getName());
|
||||
String firstCharacter = String.valueOf(repositories.getFullName().charAt(0));
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 14);
|
||||
TextDrawable drawable =
|
||||
TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.fontSize(18)
|
||||
.toUpperCase()
|
||||
.width(28)
|
||||
.height(28)
|
||||
.endConfig()
|
||||
.buildRoundRect(firstCharacter, color, 14);
|
||||
|
||||
if(repositories.getAvatarUrl() != null) {
|
||||
if(!repositories.getAvatarUrl().equals("")) {
|
||||
PicassoService.getInstance(context).get().load(repositories.getAvatarUrl()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(imgRadius, 0)).resize(120, 120).centerCrop()
|
||||
.into(image);
|
||||
}
|
||||
else {
|
||||
if (repositories.getAvatarUrl() != null) {
|
||||
if (!repositories.getAvatarUrl().equals("")) {
|
||||
PicassoService.getInstance(context)
|
||||
.get()
|
||||
.load(repositories.getAvatarUrl())
|
||||
.placeholder(R.drawable.loader_animated)
|
||||
.transform(new RoundedTransformation(imgRadius, 0))
|
||||
.resize(120, 120)
|
||||
.centerCrop()
|
||||
.into(image);
|
||||
} else {
|
||||
image.setImageDrawable(drawable);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
image.setImageDrawable(drawable);
|
||||
}
|
||||
|
||||
if(repositories.getUpdatedAt() != null) {
|
||||
if (repositories.getUpdatedAt() != null) {
|
||||
repoLastUpdated.setText(TimeHelper.formatTime(repositories.getUpdatedAt(), locale));
|
||||
repoLastUpdated.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(repositories.getUpdatedAt()), context));
|
||||
}
|
||||
else {
|
||||
repoLastUpdated.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(
|
||||
repositories.getUpdatedAt()),
|
||||
context));
|
||||
} else {
|
||||
repoLastUpdated.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(!repositories.getDescription().equals("")) {
|
||||
if (!repositories.getDescription().equals("")) {
|
||||
repoDescription.setVisibility(View.VISIBLE);
|
||||
repoDescription.setText(repositories.getDescription());
|
||||
spacerView.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
repoDescription.setVisibility(View.GONE);
|
||||
spacerView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if(isRepoAdmin == null) {
|
||||
if (isRepoAdmin == null) {
|
||||
isRepoAdmin = new CheckBox(context);
|
||||
}
|
||||
isRepoAdmin.setChecked(repositories.getPermissions().isAdmin());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.amulyakhare.textdrawable.TextDrawable;
|
|||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import java.util.List;
|
||||
import org.gitnex.tea4j.v2.models.WikiPageMetaData;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.RepoDetailActivity;
|
||||
|
@ -26,7 +27,6 @@ import org.mian.gitnex.helpers.ClickListener;
|
|||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
||||
import java.util.List;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
@ -34,7 +34,6 @@ import retrofit2.Response;
|
|||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class WikiListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
|
||||
private final Context ctx;
|
||||
|
@ -45,7 +44,12 @@ public class WikiListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
private OnLoadMoreListener loadMoreListener;
|
||||
private boolean isLoading = false, isMoreDataAvailable = true;
|
||||
|
||||
public WikiListAdapter(List<WikiPageMetaData> wikiListMain, Context ctx, String repoOwner, String repoName, FragmentWikiBinding fragmentWikiBinding) {
|
||||
public WikiListAdapter(
|
||||
List<WikiPageMetaData> wikiListMain,
|
||||
Context ctx,
|
||||
String repoOwner,
|
||||
String repoName,
|
||||
FragmentWikiBinding fragmentWikiBinding) {
|
||||
this.ctx = ctx;
|
||||
this.wikiList = wikiListMain;
|
||||
this.repoOwner = repoOwner;
|
||||
|
@ -53,8 +57,7 @@ public class WikiListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
this.fragmentWikiBinding = fragmentWikiBinding;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
@NonNull @Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
LayoutInflater inflater = LayoutInflater.from(ctx);
|
||||
return new WikiListAdapter.WikisHolder(inflater.inflate(R.layout.list_wiki, parent, false));
|
||||
|
@ -62,7 +65,10 @@ public class WikiListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
|
||||
if (position >= getItemCount() - 1
|
||||
&& isMoreDataAvailable
|
||||
&& !isLoading
|
||||
&& loadMoreListener != null) {
|
||||
isLoading = true;
|
||||
loadMoreListener.onLoadMore();
|
||||
}
|
||||
|
@ -88,7 +94,7 @@ public class WikiListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
|
||||
public void setMoreDataAvailable(boolean moreDataAvailable) {
|
||||
isMoreDataAvailable = moreDataAvailable;
|
||||
if(!isMoreDataAvailable) {
|
||||
if (!isMoreDataAvailable) {
|
||||
loadMoreListener.onLoadFinished();
|
||||
}
|
||||
}
|
||||
|
@ -109,37 +115,72 @@ public class WikiListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
notifyDataChanged();
|
||||
}
|
||||
|
||||
private void deleteWiki(final String owner, final String repo, final String pageName, int position, final Context context) {
|
||||
private void deleteWiki(
|
||||
final String owner,
|
||||
final String repo,
|
||||
final String pageName,
|
||||
int position,
|
||||
final Context context) {
|
||||
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(context, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder =
|
||||
new MaterialAlertDialogBuilder(
|
||||
context, R.style.ThemeOverlay_Material3_Dialog_Alert);
|
||||
|
||||
materialAlertDialogBuilder.setTitle(String.format(context.getString(R.string.deleteGenericTitle), pageName)).setMessage(context.getString(R.string.deleteWikiPageMessage, pageName))
|
||||
.setPositiveButton(R.string.menuDeleteText, (dialog, whichButton) -> RetrofitClient.getApiInterface(context).repoDeleteWikiPage(owner, repo, pageName).enqueue(new Callback<>() {
|
||||
materialAlertDialogBuilder
|
||||
.setTitle(String.format(context.getString(R.string.deleteGenericTitle), pageName))
|
||||
.setMessage(context.getString(R.string.deleteWikiPageMessage, pageName))
|
||||
.setPositiveButton(
|
||||
R.string.menuDeleteText,
|
||||
(dialog, whichButton) ->
|
||||
RetrofitClient.getApiInterface(context)
|
||||
.repoDeleteWikiPage(owner, repo, pageName)
|
||||
.enqueue(
|
||||
new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<Void> call, @NonNull Response<Void> response) {
|
||||
@Override
|
||||
public void onResponse(
|
||||
@NonNull Call<Void> call,
|
||||
@NonNull Response<Void> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
updateAdapter(position);
|
||||
Toasty.success(context, context.getString(R.string.wikiPageDeleted));
|
||||
if(getItemCount() == 0) {
|
||||
fragmentWikiBinding.noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
Toasty.error(context, context.getString(R.string.authorizeError));
|
||||
}
|
||||
else {
|
||||
Toasty.error(context, context.getString(R.string.genericError));
|
||||
}
|
||||
}
|
||||
if (response.isSuccessful()) {
|
||||
updateAdapter(position);
|
||||
Toasty.success(
|
||||
context,
|
||||
context.getString(
|
||||
R.string
|
||||
.wikiPageDeleted));
|
||||
if (getItemCount() == 0) {
|
||||
fragmentWikiBinding.noData
|
||||
.setVisibility(
|
||||
View.VISIBLE);
|
||||
}
|
||||
} else if (response.code() == 403) {
|
||||
Toasty.error(
|
||||
context,
|
||||
context.getString(
|
||||
R.string
|
||||
.authorizeError));
|
||||
} else {
|
||||
Toasty.error(
|
||||
context,
|
||||
context.getString(
|
||||
R.string.genericError));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
|
||||
@Override
|
||||
public void onFailure(
|
||||
@NonNull Call<Void> call,
|
||||
@NonNull Throwable t) {
|
||||
|
||||
Toasty.error(context, context.getString(R.string.genericError));
|
||||
}
|
||||
})).setNeutralButton(R.string.cancelButton, null).show();
|
||||
Toasty.error(
|
||||
context,
|
||||
context.getString(
|
||||
R.string.genericError));
|
||||
}
|
||||
}))
|
||||
.setNeutralButton(R.string.cancelButton, null)
|
||||
.show();
|
||||
}
|
||||
|
||||
public interface OnLoadMoreListener {
|
||||
|
@ -147,7 +188,6 @@ public class WikiListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
void onLoadMore();
|
||||
|
||||
void onLoadFinished();
|
||||
|
||||
}
|
||||
|
||||
class WikisHolder extends RecyclerView.ViewHolder {
|
||||
|
@ -166,46 +206,61 @@ public class WikiListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
wikiLastUpdatedBy = itemView.findViewById(R.id.wiki_last_updated_by);
|
||||
wikiMenu = itemView.findViewById(R.id.wiki_menu);
|
||||
|
||||
itemView.setOnClickListener(v -> {
|
||||
itemView.setOnClickListener(
|
||||
v -> {
|
||||
Intent intent = new Intent(ctx, WikiActivity.class);
|
||||
intent.putExtra("pageName", wikiPageMeta.getTitle());
|
||||
intent.putExtra(
|
||||
RepositoryContext.INTENT_EXTRA,
|
||||
((RepoDetailActivity) itemView.getContext()).repository);
|
||||
ctx.startActivity(intent);
|
||||
});
|
||||
|
||||
Intent intent = new Intent(ctx, WikiActivity.class);
|
||||
intent.putExtra("pageName", wikiPageMeta.getTitle());
|
||||
intent.putExtra(RepositoryContext.INTENT_EXTRA, ((RepoDetailActivity) itemView.getContext()).repository);
|
||||
ctx.startActivity(intent);
|
||||
});
|
||||
wikiMenu.setOnClickListener(
|
||||
v -> {
|
||||
Context ctx = v.getContext();
|
||||
|
||||
wikiMenu.setOnClickListener(v -> {
|
||||
View view =
|
||||
LayoutInflater.from(ctx)
|
||||
.inflate(
|
||||
R.layout.bottom_sheet_wiki_in_list,
|
||||
itemView.findViewById(android.R.id.content),
|
||||
false);
|
||||
|
||||
Context ctx = v.getContext();
|
||||
TextView bottomSheetHeader = view.findViewById(R.id.bottom_sheet_header);
|
||||
TextView editWiki = view.findViewById(R.id.edit_wiki);
|
||||
TextView deleteWiki = view.findViewById(R.id.delete_wiki);
|
||||
|
||||
View view = LayoutInflater.from(ctx).inflate(R.layout.bottom_sheet_wiki_in_list, itemView.findViewById(android.R.id.content), false);
|
||||
bottomSheetHeader.setText(wikiPageMeta.getTitle());
|
||||
|
||||
TextView bottomSheetHeader = view.findViewById(R.id.bottom_sheet_header);
|
||||
TextView editWiki = view.findViewById(R.id.edit_wiki);
|
||||
TextView deleteWiki = view.findViewById(R.id.delete_wiki);
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(ctx);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
bottomSheetHeader.setText(wikiPageMeta.getTitle());
|
||||
editWiki.setOnClickListener(
|
||||
v12 -> {
|
||||
Intent intent = new Intent(ctx, WikiActivity.class);
|
||||
intent.putExtra("pageName", wikiPageMeta.getTitle());
|
||||
intent.putExtra("action", "edit");
|
||||
intent.putExtra(
|
||||
RepositoryContext.INTENT_EXTRA,
|
||||
((RepoDetailActivity) itemView.getContext())
|
||||
.repository);
|
||||
ctx.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(ctx);
|
||||
dialog.setContentView(view);
|
||||
dialog.show();
|
||||
|
||||
editWiki.setOnClickListener(v12 -> {
|
||||
|
||||
Intent intent = new Intent(ctx, WikiActivity.class);
|
||||
intent.putExtra("pageName", wikiPageMeta.getTitle());
|
||||
intent.putExtra("action", "edit");
|
||||
intent.putExtra(RepositoryContext.INTENT_EXTRA, ((RepoDetailActivity) itemView.getContext()).repository);
|
||||
ctx.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
});
|
||||
|
||||
deleteWiki.setOnClickListener(v12 -> {
|
||||
|
||||
deleteWiki(repoOwner, repoName, wikiPageMeta.getTitle(), getAbsoluteAdapterPosition(), ctx);
|
||||
dialog.dismiss();
|
||||
});
|
||||
});
|
||||
deleteWiki.setOnClickListener(
|
||||
v12 -> {
|
||||
deleteWiki(
|
||||
repoOwner,
|
||||
repoName,
|
||||
wikiPageMeta.getTitle(),
|
||||
getAbsoluteAdapterPosition(),
|
||||
ctx);
|
||||
dialog.dismiss();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
|
@ -214,22 +269,49 @@ public class WikiListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||
this.wikiPageMeta = wikiPageMetaData;
|
||||
|
||||
pageName.setText(wikiPageMetaData.getTitle());
|
||||
wikiLastUpdatedBy.setText(HtmlCompat.fromHtml(ctx.getResources().getString(R.string.wikiAuthor, wikiPageMetaData.getLastCommit().getAuthor().getName(),
|
||||
TimeHelper.formatTime(TimeHelper.parseIso8601(wikiPageMetaData.getLastCommit().getAuthor().getDate()), ctx.getResources().getConfiguration().locale)), HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
this.wikiLastUpdatedBy.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(TimeHelper.parseIso8601(wikiPageMetaData.getLastCommit().getAuthor().getDate())), ctx));
|
||||
wikiLastUpdatedBy.setText(
|
||||
HtmlCompat.fromHtml(
|
||||
ctx.getResources()
|
||||
.getString(
|
||||
R.string.wikiAuthor,
|
||||
wikiPageMetaData.getLastCommit().getAuthor().getName(),
|
||||
TimeHelper.formatTime(
|
||||
TimeHelper.parseIso8601(
|
||||
wikiPageMetaData
|
||||
.getLastCommit()
|
||||
.getAuthor()
|
||||
.getDate()),
|
||||
ctx.getResources().getConfiguration().locale)),
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
this.wikiLastUpdatedBy.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(
|
||||
TimeHelper.parseIso8601(
|
||||
wikiPageMetaData
|
||||
.getLastCommit()
|
||||
.getAuthor()
|
||||
.getDate())),
|
||||
ctx));
|
||||
|
||||
ColorGenerator generator = ColorGenerator.Companion.getMATERIAL();
|
||||
int color = generator.getColor(wikiPageMetaData.getTitle());
|
||||
String firstCharacter = String.valueOf(wikiPageMetaData.getTitle().charAt(0));
|
||||
|
||||
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 14);
|
||||
TextDrawable drawable =
|
||||
TextDrawable.builder()
|
||||
.beginConfig()
|
||||
.useFont(Typeface.DEFAULT)
|
||||
.fontSize(18)
|
||||
.toUpperCase()
|
||||
.width(28)
|
||||
.height(28)
|
||||
.endConfig()
|
||||
.buildRoundRect(firstCharacter, color, 14);
|
||||
avatar.setImageDrawable(drawable);
|
||||
|
||||
if(!((RepoDetailActivity) ctx).repository.getPermissions().isPush()) {
|
||||
if (!((RepoDetailActivity) ctx).repository.getPermissions().isPush()) {
|
||||
wikiMenu.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,16 +54,36 @@ public class MainApplication extends Application {
|
|||
|
||||
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder();
|
||||
|
||||
ACRABuilder.withBuildConfigClass(BuildConfig.class).withReportContent(ReportField.ANDROID_VERSION, ReportField.PHONE_MODEL, ReportField.STACK_TRACE, ReportField.AVAILABLE_MEM_SIZE, ReportField.BRAND)
|
||||
.setReportFormat(StringFormat.KEY_VALUE_LIST);
|
||||
ACRABuilder.withBuildConfigClass(BuildConfig.class)
|
||||
.withReportContent(
|
||||
ReportField.ANDROID_VERSION,
|
||||
ReportField.PHONE_MODEL,
|
||||
ReportField.STACK_TRACE,
|
||||
ReportField.AVAILABLE_MEM_SIZE,
|
||||
ReportField.BRAND)
|
||||
.setReportFormat(StringFormat.KEY_VALUE_LIST);
|
||||
|
||||
ACRABuilder.withPluginConfigurations(new NotificationConfigurationBuilder().withTitle(getString(R.string.crashTitle)).withResIcon(R.drawable.gitnex_transparent).withChannelName(getString(R.string.setCrashReports))
|
||||
.withText(getString(R.string.crashMessage)).build());
|
||||
ACRABuilder.withPluginConfigurations(
|
||||
new NotificationConfigurationBuilder()
|
||||
.withTitle(getString(R.string.crashTitle))
|
||||
.withResIcon(R.drawable.gitnex_transparent)
|
||||
.withChannelName(getString(R.string.setCrashReports))
|
||||
.withText(getString(R.string.crashMessage))
|
||||
.build());
|
||||
|
||||
ACRABuilder.withPluginConfigurations(new MailSenderConfigurationBuilder().withMailTo(getResources().getString(R.string.appEmail))
|
||||
.withSubject(getResources().getString(R.string.crashReportEmailSubject, AppUtil.getAppBuildNo(context))).withReportAsFile(true).build());
|
||||
ACRABuilder.withPluginConfigurations(
|
||||
new MailSenderConfigurationBuilder()
|
||||
.withMailTo(getResources().getString(R.string.appEmail))
|
||||
.withSubject(
|
||||
getResources()
|
||||
.getString(
|
||||
R.string.crashReportEmailSubject,
|
||||
AppUtil.getAppBuildNo(context)))
|
||||
.withReportAsFile(true)
|
||||
.build());
|
||||
|
||||
ACRABuilder.withPluginConfigurations(new LimiterConfigurationBuilder().withEnabled(true).build());
|
||||
ACRABuilder.withPluginConfigurations(
|
||||
new LimiterConfigurationBuilder().withEnabled(true).build());
|
||||
|
||||
ACRA.init(this, ACRABuilder);
|
||||
}
|
||||
|
|
|
@ -2,14 +2,13 @@ package org.mian.gitnex.database.api;
|
|||
|
||||
import android.content.Context;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import java.util.List;
|
||||
import org.mian.gitnex.database.dao.NotesDao;
|
||||
import org.mian.gitnex.database.models.Notes;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class NotesApi extends BaseApi {
|
||||
|
||||
private final NotesDao notesDao;
|
||||
|
@ -55,7 +54,7 @@ public class NotesApi extends BaseApi {
|
|||
public void deleteNote(final int noteId) {
|
||||
final Notes note = notesDao.fetchNoteById(noteId);
|
||||
|
||||
if(note != null) {
|
||||
if (note != null) {
|
||||
executorService.execute(() -> notesDao.deleteNote(noteId));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,12 @@ import androidx.lifecycle.LiveData;
|
|||
import androidx.room.Dao;
|
||||
import androidx.room.Insert;
|
||||
import androidx.room.Query;
|
||||
import org.mian.gitnex.database.models.Notes;
|
||||
import java.util.List;
|
||||
import org.mian.gitnex.database.models.Notes;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
@Dao
|
||||
public interface NotesDao {
|
||||
|
||||
|
|
|
@ -19,8 +19,10 @@ import org.mian.gitnex.database.models.UserAccount;
|
|||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
@Database(entities = {Draft.class, Repository.class, UserAccount.class, Notes.class}, version = 7, exportSchema = false)
|
||||
@Database(
|
||||
entities = {Draft.class, Repository.class, UserAccount.class, Notes.class},
|
||||
version = 7,
|
||||
exportSchema = false)
|
||||
public abstract class GitnexDatabase extends RoomDatabase {
|
||||
|
||||
private static final String DB_NAME = "gitnex";
|
||||
|
@ -62,18 +64,21 @@ public abstract class GitnexDatabase extends RoomDatabase {
|
|||
private static final Migration MIGRATION_5_6 =
|
||||
new Migration(5, 6) {
|
||||
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("ALTER TABLE 'Repositories' ADD COLUMN 'mostVisited' INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
};
|
||||
private static final Migration MIGRATION_6_7 = new Migration(6, 7) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL(
|
||||
"ALTER TABLE 'Repositories' ADD COLUMN 'mostVisited' INTEGER NOT NULL DEFAULT 0");
|
||||
}
|
||||
};
|
||||
private static final Migration MIGRATION_6_7 =
|
||||
new Migration(6, 7) {
|
||||
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("CREATE TABLE IF NOT EXISTS 'Notes' ('noteId' INTEGER NOT NULL, 'content' TEXT, 'datetime' INTEGER, 'modified' INTEGER, PRIMARY KEY('noteid'))");
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL(
|
||||
"CREATE TABLE IF NOT EXISTS 'Notes' ('noteId' INTEGER NOT NULL, 'content' TEXT, 'datetime' INTEGER, 'modified' INTEGER, PRIMARY KEY('noteid'))");
|
||||
}
|
||||
};
|
||||
private static volatile GitnexDatabase gitnexDatabase;
|
||||
|
||||
public static GitnexDatabase getDatabaseInstance(Context context) {
|
||||
|
@ -82,10 +87,18 @@ public abstract class GitnexDatabase extends RoomDatabase {
|
|||
synchronized (GitnexDatabase.class) {
|
||||
if (gitnexDatabase == null) {
|
||||
|
||||
gitnexDatabase = Room.databaseBuilder(context, GitnexDatabase.class, DB_NAME)
|
||||
//.fallbackToDestructiveMigration()
|
||||
.allowMainThreadQueries().addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6, MIGRATION_6_7).build();
|
||||
|
||||
gitnexDatabase =
|
||||
Room.databaseBuilder(context, GitnexDatabase.class, DB_NAME)
|
||||
// .fallbackToDestructiveMigration()
|
||||
.allowMainThreadQueries()
|
||||
.addMigrations(
|
||||
MIGRATION_1_2,
|
||||
MIGRATION_2_3,
|
||||
MIGRATION_3_4,
|
||||
MIGRATION_4_5,
|
||||
MIGRATION_5_6,
|
||||
MIGRATION_6_7)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,15 +8,13 @@ import java.io.Serializable;
|
|||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
@Entity(tableName = "Notes")
|
||||
public class Notes implements Serializable {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
private int noteId;
|
||||
|
||||
@Nullable
|
||||
private String content;
|
||||
@Nullable private String content;
|
||||
private Integer datetime;
|
||||
private Integer modified;
|
||||
|
||||
|
@ -28,8 +26,7 @@ public class Notes implements Serializable {
|
|||
this.noteId = noteId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getContent() {
|
||||
@Nullable public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
|
|
|
@ -205,17 +205,52 @@ public class CommitDetailFragment extends Fragment {
|
|||
binding.commitBody.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(!Objects.equals(commitsModel.getCommit().getCommitter().getEmail(), commitsModel.getCommit().getCommitter().getEmail())) {
|
||||
binding.commitAuthorAndCommitter.setText(HtmlCompat.fromHtml(
|
||||
CommitDetailFragment.this.getString(R.string.commitAuthoredByAndCommittedByWhen, commitsModel.getCommit().getAuthor().getName(), commitsModel.getCommit().getCommitter().getName(),
|
||||
TimeHelper.formatTime(TimeHelper.parseIso8601(commitsModel.getCommit().getCommitter().getDate()), getResources().getConfiguration().locale)),
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
}
|
||||
else {
|
||||
binding.commitAuthorAndCommitter.setText(HtmlCompat.fromHtml(CommitDetailFragment.this.getString(R.string.commitCommittedByWhen, commitsModel.getCommit().getCommitter().getName(),
|
||||
TimeHelper.formatTime(TimeHelper.parseIso8601(commitsModel.getCommit().getCommitter().getDate()), getResources().getConfiguration().locale)),
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
}
|
||||
if (!Objects.equals(
|
||||
commitsModel.getCommit().getCommitter().getEmail(),
|
||||
commitsModel.getCommit().getCommitter().getEmail())) {
|
||||
binding.commitAuthorAndCommitter.setText(
|
||||
HtmlCompat.fromHtml(
|
||||
CommitDetailFragment.this.getString(
|
||||
R.string
|
||||
.commitAuthoredByAndCommittedByWhen,
|
||||
commitsModel
|
||||
.getCommit()
|
||||
.getAuthor()
|
||||
.getName(),
|
||||
commitsModel
|
||||
.getCommit()
|
||||
.getCommitter()
|
||||
.getName(),
|
||||
TimeHelper.formatTime(
|
||||
TimeHelper.parseIso8601(
|
||||
commitsModel
|
||||
.getCommit()
|
||||
.getCommitter()
|
||||
.getDate()),
|
||||
getResources()
|
||||
.getConfiguration()
|
||||
.locale)),
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
} else {
|
||||
binding.commitAuthorAndCommitter.setText(
|
||||
HtmlCompat.fromHtml(
|
||||
CommitDetailFragment.this.getString(
|
||||
R.string.commitCommittedByWhen,
|
||||
commitsModel
|
||||
.getCommit()
|
||||
.getCommitter()
|
||||
.getName(),
|
||||
TimeHelper.formatTime(
|
||||
TimeHelper.parseIso8601(
|
||||
commitsModel
|
||||
.getCommit()
|
||||
.getCommitter()
|
||||
.getDate()),
|
||||
getResources()
|
||||
.getConfiguration()
|
||||
.locale)),
|
||||
HtmlCompat.FROM_HTML_MODE_COMPACT));
|
||||
}
|
||||
|
||||
if (commitsModel.getAuthor() != null
|
||||
&& commitsModel.getAuthor().getAvatarUrl() != null
|
||||
|
|
|
@ -17,6 +17,8 @@ import androidx.appcompat.widget.SearchView;
|
|||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.CreateNoteActivity;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
|
@ -26,13 +28,10 @@ import org.mian.gitnex.database.api.NotesApi;
|
|||
import org.mian.gitnex.database.models.Notes;
|
||||
import org.mian.gitnex.databinding.FragmentNotesBinding;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class NotesFragment extends Fragment {
|
||||
|
||||
private FragmentNotesBinding fragmentNotesBinding;
|
||||
|
@ -43,21 +42,24 @@ public class NotesFragment extends Fragment {
|
|||
private Intent noteIntent;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(
|
||||
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
fragmentNotesBinding = FragmentNotesBinding.inflate(inflater, container, false);
|
||||
|
||||
ctx = getContext();
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.navNotes));
|
||||
((MainActivity) requireActivity())
|
||||
.setActionBarTitle(getResources().getString(R.string.navNotes));
|
||||
|
||||
noteIntent = new Intent(ctx, CreateNoteActivity.class);
|
||||
|
||||
fragmentNotesBinding.newNote.setOnClickListener(view -> {
|
||||
noteIntent.putExtra("action", "add");
|
||||
ctx.startActivity(noteIntent);
|
||||
});
|
||||
fragmentNotesBinding.newNote.setOnClickListener(
|
||||
view -> {
|
||||
noteIntent.putExtra("action", "add");
|
||||
ctx.startActivity(noteIntent);
|
||||
});
|
||||
|
||||
notesList = new ArrayList<>();
|
||||
notesApi = BaseApi.getInstance(ctx, NotesApi.class);
|
||||
|
@ -70,13 +72,18 @@ public class NotesFragment extends Fragment {
|
|||
|
||||
adapter = new NotesAdapter(ctx, notesList);
|
||||
|
||||
fragmentNotesBinding.pullToRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
notesList.clear();
|
||||
fragmentNotesBinding.pullToRefresh.setRefreshing(false);
|
||||
fragmentNotesBinding.progressBar.setVisibility(View.VISIBLE);
|
||||
fetchDataAsync();
|
||||
}, 250));
|
||||
fragmentNotesBinding.pullToRefresh.setOnRefreshListener(
|
||||
() ->
|
||||
new Handler(Looper.getMainLooper())
|
||||
.postDelayed(
|
||||
() -> {
|
||||
notesList.clear();
|
||||
fragmentNotesBinding.pullToRefresh.setRefreshing(false);
|
||||
fragmentNotesBinding.progressBar.setVisibility(
|
||||
View.VISIBLE);
|
||||
fetchDataAsync();
|
||||
},
|
||||
250));
|
||||
|
||||
fetchDataAsync();
|
||||
|
||||
|
@ -91,37 +98,38 @@ public class NotesFragment extends Fragment {
|
|||
|
||||
private void fetchDataAsync() {
|
||||
|
||||
notesApi.fetchAllNotes().observe(getViewLifecycleOwner(), allNotes -> {
|
||||
notesApi.fetchAllNotes()
|
||||
.observe(
|
||||
getViewLifecycleOwner(),
|
||||
allNotes -> {
|
||||
fragmentNotesBinding.pullToRefresh.setRefreshing(false);
|
||||
assert allNotes != null;
|
||||
if (allNotes.size() > 0) {
|
||||
|
||||
fragmentNotesBinding.pullToRefresh.setRefreshing(false);
|
||||
assert allNotes != null;
|
||||
if(allNotes.size() > 0) {
|
||||
notesList.clear();
|
||||
fragmentNotesBinding.noData.setVisibility(View.GONE);
|
||||
notesList.addAll(allNotes);
|
||||
adapter.notifyDataChanged();
|
||||
fragmentNotesBinding.recyclerView.setAdapter(adapter);
|
||||
} else {
|
||||
|
||||
notesList.clear();
|
||||
fragmentNotesBinding.noData.setVisibility(View.GONE);
|
||||
notesList.addAll(allNotes);
|
||||
adapter.notifyDataChanged();
|
||||
fragmentNotesBinding.recyclerView.setAdapter(adapter);
|
||||
}
|
||||
else {
|
||||
|
||||
fragmentNotesBinding.noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
fragmentNotesBinding.progressBar.setVisibility(View.GONE);
|
||||
});
|
||||
fragmentNotesBinding.noData.setVisibility(View.VISIBLE);
|
||||
}
|
||||
fragmentNotesBinding.progressBar.setVisibility(View.GONE);
|
||||
});
|
||||
}
|
||||
|
||||
private void filter(String text) {
|
||||
|
||||
List<Notes> arr = new ArrayList<>();
|
||||
|
||||
for(Notes d : notesList) {
|
||||
for (Notes d : notesList) {
|
||||
|
||||
if(d == null || d.getContent() == null) {
|
||||
if (d == null || d.getContent() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(d.getContent().toLowerCase().contains(text)) {
|
||||
if (d.getContent().toLowerCase().contains(text)) {
|
||||
arr.add(d);
|
||||
}
|
||||
}
|
||||
|
@ -131,14 +139,14 @@ public class NotesFragment extends Fragment {
|
|||
|
||||
public void deleteAllNotes() {
|
||||
|
||||
if(notesList.size() > 0) {
|
||||
if (notesList.size() > 0) {
|
||||
|
||||
notesApi.deleteAllNotes();
|
||||
notesList.clear();
|
||||
adapter.notifyDataChanged();
|
||||
Toasty.success(ctx, ctx.getResources().getQuantityString(R.plurals.noteDeleteMessage, 2));
|
||||
}
|
||||
else {
|
||||
Toasty.success(
|
||||
ctx, ctx.getResources().getQuantityString(R.plurals.noteDeleteMessage, 2));
|
||||
} else {
|
||||
Toasty.warning(ctx, getResources().getString(R.string.noDataFound));
|
||||
}
|
||||
}
|
||||
|
@ -154,39 +162,43 @@ public class NotesFragment extends Fragment {
|
|||
SearchView searchView = (SearchView) searchItem.getActionView();
|
||||
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
searchView.setOnQueryTextListener(
|
||||
new SearchView.OnQueryTextListener() {
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
|
||||
filter(newText);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
filter(newText);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
if(item.getItemId() == R.id.reset_menu_item) {
|
||||
if (item.getItemId() == R.id.reset_menu_item) {
|
||||
|
||||
if(notesList.size() == 0) {
|
||||
if (notesList.size() == 0) {
|
||||
Toasty.warning(ctx, getResources().getString(R.string.noDataFound));
|
||||
}
|
||||
else {
|
||||
new MaterialAlertDialogBuilder(ctx).setTitle(R.string.menuDeleteText)
|
||||
.setMessage(R.string.notesAllDeletionMessage)
|
||||
.setPositiveButton(R.string.menuDeleteText, (dialog, which) -> {
|
||||
|
||||
deleteAllNotes();
|
||||
dialog.dismiss();
|
||||
}).setNeutralButton(R.string.cancelButton, null).show();
|
||||
} else {
|
||||
new MaterialAlertDialogBuilder(ctx)
|
||||
.setTitle(R.string.menuDeleteText)
|
||||
.setMessage(R.string.notesAllDeletionMessage)
|
||||
.setPositiveButton(
|
||||
R.string.menuDeleteText,
|
||||
(dialog, which) -> {
|
||||
deleteAllNotes();
|
||||
dialog.dismiss();
|
||||
})
|
||||
.setNeutralButton(R.string.cancelButton, null)
|
||||
.show();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,9 @@ import android.widget.TextView;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.gitnex.tea4j.v2.models.Organization;
|
||||
import org.gitnex.tea4j.v2.models.Repository;
|
||||
|
@ -31,9 +34,6 @@ import org.mian.gitnex.helpers.Markdown;
|
|||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.contexts.RepositoryContext;
|
||||
import java.io.IOException;
|
||||
import java.util.Locale;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
@ -41,7 +41,6 @@ import retrofit2.Response;
|
|||
/**
|
||||
* @author M M Arif
|
||||
*/
|
||||
|
||||
public class RepoInfoFragment extends Fragment {
|
||||
|
||||
private Context ctx;
|
||||
|
@ -51,8 +50,7 @@ public class RepoInfoFragment extends Fragment {
|
|||
|
||||
private RepositoryContext repository;
|
||||
|
||||
public RepoInfoFragment() {
|
||||
}
|
||||
public RepoInfoFragment() {}
|
||||
|
||||
public static RepoInfoFragment newInstance(RepositoryContext repository) {
|
||||
RepoInfoFragment fragment = new RepoInfoFragment();
|
||||
|
@ -67,7 +65,8 @@ public class RepoInfoFragment extends Fragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
public View onCreateView(
|
||||
@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
binding = FragmentRepoInfoBinding.inflate(inflater, container, false);
|
||||
ctx = getContext();
|
||||
|
@ -80,41 +79,46 @@ public class RepoInfoFragment extends Fragment {
|
|||
|
||||
setRepoInfo(locale);
|
||||
|
||||
if(isExpandViewVisible()) {
|
||||
if (isExpandViewVisible()) {
|
||||
toggleExpandView();
|
||||
}
|
||||
|
||||
if(!isExpandViewMetaVisible()) {
|
||||
if (!isExpandViewMetaVisible()) {
|
||||
toggleExpandViewMeta();
|
||||
}
|
||||
|
||||
binding.fileContentsFrameHeader.setOnClickListener(v1 -> toggleExpandView());
|
||||
binding.repoMetaFrameHeader.setOnClickListener(v12 -> toggleExpandViewMeta());
|
||||
|
||||
binding.repoMetaStarsFrame.setOnClickListener(metaStars -> ctx.startActivity(repository.getIntent(ctx, RepoStargazersActivity.class)));
|
||||
binding.repoMetaStarsFrame.setOnClickListener(
|
||||
metaStars ->
|
||||
ctx.startActivity(repository.getIntent(ctx, RepoStargazersActivity.class)));
|
||||
|
||||
binding.repoMetaWatchersFrame.setOnClickListener(metaWatchers -> ctx.startActivity(repository.getIntent(ctx, RepoWatchersActivity.class)));
|
||||
binding.repoMetaWatchersFrame.setOnClickListener(
|
||||
metaWatchers ->
|
||||
ctx.startActivity(repository.getIntent(ctx, RepoWatchersActivity.class)));
|
||||
|
||||
binding.repoMetaForksFrame.setOnClickListener(metaForks -> ctx.startActivity(repository.getIntent(ctx, RepoForksActivity.class)));
|
||||
binding.repoMetaForksFrame.setOnClickListener(
|
||||
metaForks -> ctx.startActivity(repository.getIntent(ctx, RepoForksActivity.class)));
|
||||
|
||||
binding.repoMetaPullRequestsFrame.setOnClickListener(metaPR -> ((RepoDetailActivity) requireActivity()).viewPager.setCurrentItem(3));
|
||||
binding.repoMetaPullRequestsFrame.setOnClickListener(
|
||||
metaPR -> ((RepoDetailActivity) requireActivity()).viewPager.setCurrentItem(3));
|
||||
|
||||
return binding.getRoot();
|
||||
}
|
||||
|
||||
private void toggleExpandView() {
|
||||
|
||||
if(binding.repoFileContents.getVisibility() == View.GONE) {
|
||||
if (binding.repoFileContents.getVisibility() == View.GONE) {
|
||||
binding.repoFilenameExpandCollapse.setImageResource(R.drawable.ic_chevron_up);
|
||||
binding.repoFileContents.setVisibility(View.VISIBLE);
|
||||
//Animation slide_down = AnimationUtils.loadAnimation(getContext(), R.anim.slide_down);
|
||||
//binding.fileContentsFrame.startAnimation(slide_down);
|
||||
}
|
||||
else {
|
||||
// Animation slide_down = AnimationUtils.loadAnimation(getContext(), R.anim.slide_down);
|
||||
// binding.fileContentsFrame.startAnimation(slide_down);
|
||||
} else {
|
||||
binding.repoFilenameExpandCollapse.setImageResource(R.drawable.ic_chevron_down);
|
||||
binding.repoFileContents.setVisibility(View.GONE);
|
||||
//Animation slide_up = AnimationUtils.loadAnimation(getContext(), R.anim.slide_up);
|
||||
//binding.fileContentsFrame.startAnimation(slide_up);
|
||||
// Animation slide_up = AnimationUtils.loadAnimation(getContext(), R.anim.slide_up);
|
||||
// binding.fileContentsFrame.startAnimation(slide_up);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,17 +128,16 @@ public class RepoInfoFragment extends Fragment {
|
|||
|
||||
private void toggleExpandViewMeta() {
|
||||
|
||||
if(binding.repoMetaFrame.getVisibility() == View.GONE) {
|
||||
if (binding.repoMetaFrame.getVisibility() == View.GONE) {
|
||||
binding.repoMetaDataExpandCollapse.setImageResource(R.drawable.ic_chevron_up);
|
||||
binding.repoMetaFrame.setVisibility(View.VISIBLE);
|
||||
//Animation slide_down = AnimationUtils.loadAnimation(getContext(), R.anim.slide_down);
|
||||
//binding.repoMetaFrame.startAnimation(slide_down);
|
||||
}
|
||||
else {
|
||||
// Animation slide_down = AnimationUtils.loadAnimation(getContext(), R.anim.slide_down);
|
||||
// binding.repoMetaFrame.startAnimation(slide_down);
|
||||
} else {
|
||||
binding.repoMetaDataExpandCollapse.setImageResource(R.drawable.ic_chevron_down);
|
||||
binding.repoMetaFrame.setVisibility(View.GONE);
|
||||
//Animation slide_up = AnimationUtils.loadAnimation(getContext(), R.anim.slide_up);
|
||||
//binding.repoMetaFrame.startAnimation(slide_up);
|
||||
// Animation slide_up = AnimationUtils.loadAnimation(getContext(), R.anim.slide_up);
|
||||
// binding.repoMetaFrame.startAnimation(slide_up);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,184 +148,245 @@ public class RepoInfoFragment extends Fragment {
|
|||
private void setRepoInfo(Locale locale) {
|
||||
Repository repoInfo = repository.getRepository();
|
||||
|
||||
if(isAdded()) {
|
||||
if (isAdded()) {
|
||||
assert repoInfo != null;
|
||||
binding.repoMetaOwner.setText(repoInfo.getOwner().getLogin());
|
||||
binding.repoMetaOwner.setOnClickListener((v) -> RetrofitClient.getApiInterface(ctx).orgGet(repository.getOwner()).enqueue(new Callback<>() {
|
||||
binding.repoMetaOwner.setOnClickListener(
|
||||
(v) ->
|
||||
RetrofitClient.getApiInterface(ctx)
|
||||
.orgGet(repository.getOwner())
|
||||
.enqueue(
|
||||
new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NotNull Call<Organization> call, @NotNull Response<Organization> response) {
|
||||
Intent intent = new Intent(ctx, response.isSuccessful() ? OrganizationDetailActivity.class : ProfileActivity.class);
|
||||
intent.putExtra(response.isSuccessful() ? "orgName" : "username", repository.getOwner());
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
}
|
||||
@Override
|
||||
public void onResponse(
|
||||
@NotNull Call<Organization> call,
|
||||
@NotNull Response<Organization> response) {
|
||||
Intent intent =
|
||||
new Intent(
|
||||
ctx,
|
||||
response.isSuccessful()
|
||||
? OrganizationDetailActivity
|
||||
.class
|
||||
: ProfileActivity
|
||||
.class);
|
||||
intent.putExtra(
|
||||
response.isSuccessful()
|
||||
? "orgName"
|
||||
: "username",
|
||||
repository.getOwner());
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull Call<Organization> call, @NotNull Throwable t) {
|
||||
}
|
||||
}));
|
||||
@Override
|
||||
public void onFailure(
|
||||
@NotNull Call<Organization> call,
|
||||
@NotNull Throwable t) {}
|
||||
}));
|
||||
binding.repoMetaName.setText(repoInfo.getName());
|
||||
|
||||
if(!repoInfo.getDescription().isEmpty()) {
|
||||
if (!repoInfo.getDescription().isEmpty()) {
|
||||
Markdown.render(ctx, repoInfo.getDescription(), binding.repoMetaDescription);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
binding.repoMetaDescription.setText(getString(R.string.noDataDescription));
|
||||
}
|
||||
|
||||
binding.repoMetaStars.setText(String.valueOf(repoInfo.getStarsCount()));
|
||||
|
||||
if(repoInfo.getOpenPrCounter() != null) {
|
||||
if (repoInfo.getOpenPrCounter() != null) {
|
||||
binding.repoMetaPullRequests.setText(String.valueOf(repoInfo.getOpenPrCounter()));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
binding.repoMetaPullRequestsFrame.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
binding.repoMetaForks.setText(String.valueOf(repoInfo.getForksCount()));
|
||||
binding.repoMetaWatchers.setText(String.valueOf(repoInfo.getWatchersCount()));
|
||||
binding.repoMetaSize.setText(FileUtils.byteCountToDisplaySize(repoInfo.getSize() * 1024));
|
||||
binding.repoMetaSize.setText(
|
||||
FileUtils.byteCountToDisplaySize(repoInfo.getSize() * 1024));
|
||||
|
||||
binding.repoMetaCreatedAt.setText(TimeHelper.formatTime(repoInfo.getCreatedAt(), locale));
|
||||
binding.repoMetaCreatedAt.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(repoInfo.getCreatedAt()), ctx));
|
||||
binding.repoMetaCreatedAt.setText(
|
||||
TimeHelper.formatTime(repoInfo.getCreatedAt(), locale));
|
||||
binding.repoMetaCreatedAt.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(repoInfo.getCreatedAt()),
|
||||
ctx));
|
||||
|
||||
String repoMetaUpdatedAt = TimeHelper.formatTime(repoInfo.getUpdatedAt(), locale);
|
||||
|
||||
String website = (repoInfo.getWebsite().isEmpty()) ? getResources().getString(R.string.noDataWebsite) : repoInfo.getWebsite();
|
||||
String website =
|
||||
(repoInfo.getWebsite().isEmpty())
|
||||
? getResources().getString(R.string.noDataWebsite)
|
||||
: repoInfo.getWebsite();
|
||||
binding.repoMetaWebsite.setText(website);
|
||||
binding.repoMetaWebsite.setLinksClickable(false);
|
||||
binding.websiteFrame.setOnClickListener((v) -> {
|
||||
if(!repoInfo.getWebsite().isEmpty()) {
|
||||
AppUtil.openUrlInBrowser(requireContext(), repoInfo.getWebsite());
|
||||
}
|
||||
});
|
||||
binding.websiteFrame.setOnClickListener(
|
||||
(v) -> {
|
||||
if (!repoInfo.getWebsite().isEmpty()) {
|
||||
AppUtil.openUrlInBrowser(requireContext(), repoInfo.getWebsite());
|
||||
}
|
||||
});
|
||||
|
||||
binding.repoAdditionalButton.setOnClickListener(v -> {
|
||||
binding.repoAdditionalButton.setOnClickListener(
|
||||
v -> {
|
||||
View view =
|
||||
LayoutInflater.from(ctx)
|
||||
.inflate(R.layout.layout_repo_more_info, null);
|
||||
|
||||
View view = LayoutInflater.from(ctx).inflate(R.layout.layout_repo_more_info, null);
|
||||
TextView defaultBranchHeader = view.findViewById(R.id.defaultBranchHeader);
|
||||
TextView defaultBranchContent =
|
||||
view.findViewById(R.id.defaultBranchContent);
|
||||
|
||||
TextView defaultBranchHeader = view.findViewById(R.id.defaultBranchHeader);
|
||||
TextView defaultBranchContent = view.findViewById(R.id.defaultBranchContent);
|
||||
TextView lastUpdatedHeader = view.findViewById(R.id.lastUpdatedHeader);
|
||||
TextView lastUpdatedContent = view.findViewById(R.id.lastUpdatedContent);
|
||||
|
||||
TextView lastUpdatedHeader = view.findViewById(R.id.lastUpdatedHeader);
|
||||
TextView lastUpdatedContent = view.findViewById(R.id.lastUpdatedContent);
|
||||
TextView sshUrlHeader = view.findViewById(R.id.sshUrlHeader);
|
||||
TextView sshUrlContent = view.findViewById(R.id.sshUrlContent);
|
||||
|
||||
TextView sshUrlHeader = view.findViewById(R.id.sshUrlHeader);
|
||||
TextView sshUrlContent = view.findViewById(R.id.sshUrlContent);
|
||||
TextView cloneUrlHeader = view.findViewById(R.id.cloneUrlHeader);
|
||||
TextView cloneUrlContent = view.findViewById(R.id.cloneUrlContent);
|
||||
|
||||
TextView cloneUrlHeader = view.findViewById(R.id.cloneUrlHeader);
|
||||
TextView cloneUrlContent = view.findViewById(R.id.cloneUrlContent);
|
||||
TextView repoUrlHeader = view.findViewById(R.id.repoUrlHeader);
|
||||
TextView repoUrlContent = view.findViewById(R.id.repoUrlContent);
|
||||
|
||||
TextView repoUrlHeader = view.findViewById(R.id.repoUrlHeader);
|
||||
TextView repoUrlContent = view.findViewById(R.id.repoUrlContent);
|
||||
defaultBranchHeader.setText(getString(R.string.infoTabRepoDefaultBranch));
|
||||
defaultBranchContent.setText(repoInfo.getDefaultBranch());
|
||||
|
||||
defaultBranchHeader.setText(getString(R.string.infoTabRepoDefaultBranch));
|
||||
defaultBranchContent.setText(repoInfo.getDefaultBranch());
|
||||
lastUpdatedHeader.setText(getString(R.string.infoTabRepoUpdatedAt));
|
||||
lastUpdatedContent.setText(repoMetaUpdatedAt);
|
||||
|
||||
lastUpdatedHeader.setText(getString(R.string.infoTabRepoUpdatedAt));
|
||||
lastUpdatedContent.setText(repoMetaUpdatedAt);
|
||||
sshUrlHeader.setText(getString(R.string.infoTabRepoSshUrl));
|
||||
sshUrlContent.setText(repoInfo.getSshUrl());
|
||||
|
||||
sshUrlHeader.setText(getString(R.string.infoTabRepoSshUrl));
|
||||
sshUrlContent.setText(repoInfo.getSshUrl());
|
||||
cloneUrlHeader.setText(getString(R.string.infoTabRepoCloneUrl));
|
||||
cloneUrlContent.setText(repoInfo.getCloneUrl());
|
||||
|
||||
cloneUrlHeader.setText(getString(R.string.infoTabRepoCloneUrl));
|
||||
cloneUrlContent.setText(repoInfo.getCloneUrl());
|
||||
repoUrlHeader.setText(getString(R.string.infoTabRepoRepoUrl));
|
||||
repoUrlContent.setText(repoInfo.getHtmlUrl());
|
||||
|
||||
repoUrlHeader.setText(getString(R.string.infoTabRepoRepoUrl));
|
||||
repoUrlContent.setText(repoInfo.getHtmlUrl());
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder =
|
||||
new MaterialAlertDialogBuilder(ctx)
|
||||
.setTitle(R.string.infoMoreInformation)
|
||||
.setView(view)
|
||||
.setNeutralButton(getString(R.string.close), null);
|
||||
|
||||
materialAlertDialogBuilder.create().show();
|
||||
});
|
||||
|
||||
MaterialAlertDialogBuilder materialAlertDialogBuilder = new MaterialAlertDialogBuilder(ctx).setTitle(R.string.infoMoreInformation).setView(view).setNeutralButton(getString(R.string.close), null);
|
||||
|
||||
materialAlertDialogBuilder.create().show();
|
||||
});
|
||||
|
||||
if(repoInfo.isArchived()) {
|
||||
if (repoInfo.isArchived()) {
|
||||
binding.repoIsArchived.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
binding.repoIsArchived.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(repoInfo.isFork()) {
|
||||
if (repoInfo.isFork()) {
|
||||
binding.repoForkFrame.setVisibility(View.VISIBLE);
|
||||
binding.repoForkFrame.setOnClickListener((v) -> {
|
||||
Intent parent = new RepositoryContext(repoInfo.getParent(), requireContext()).getIntent(requireContext(), RepoDetailActivity.class);
|
||||
startActivity(parent);
|
||||
});
|
||||
binding.repoFork.setText(getString(R.string.repoForkOf, repoInfo.getParent().getFullName()));
|
||||
}
|
||||
else {
|
||||
binding.repoForkFrame.setOnClickListener(
|
||||
(v) -> {
|
||||
Intent parent =
|
||||
new RepositoryContext(repoInfo.getParent(), requireContext())
|
||||
.getIntent(requireContext(), RepoDetailActivity.class);
|
||||
startActivity(parent);
|
||||
});
|
||||
binding.repoFork.setText(
|
||||
getString(R.string.repoForkOf, repoInfo.getParent().getFullName()));
|
||||
} else {
|
||||
binding.repoForkFrame.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
getFileContents(repository.getOwner(), repository.getName(), getResources().getString(R.string.defaultFilename), repoInfo.getDefaultBranch());
|
||||
getFileContents(
|
||||
repository.getOwner(),
|
||||
repository.getName(),
|
||||
getResources().getString(R.string.defaultFilename),
|
||||
repoInfo.getDefaultBranch());
|
||||
|
||||
pageContent.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void getFileContents(final String owner, String repo, final String filename, final String defBranch) {
|
||||
private void getFileContents(
|
||||
final String owner, String repo, final String filename, final String defBranch) {
|
||||
|
||||
Call<ResponseBody> call = RetrofitClient.getWebInterface(getContext()).getFileContents(owner, repo, defBranch, filename);
|
||||
Call<ResponseBody> call =
|
||||
RetrofitClient.getWebInterface(getContext())
|
||||
.getFileContents(owner, repo, defBranch, filename);
|
||||
|
||||
call.enqueue(new Callback<>() {
|
||||
call.enqueue(
|
||||
new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull retrofit2.Response<ResponseBody> response) {
|
||||
@Override
|
||||
public void onResponse(
|
||||
@NonNull Call<ResponseBody> call,
|
||||
@NonNull retrofit2.Response<ResponseBody> response) {
|
||||
|
||||
if(isAdded()) {
|
||||
if (isAdded()) {
|
||||
|
||||
switch(response.code()) {
|
||||
switch (response.code()) {
|
||||
case 200:
|
||||
assert response.body() != null;
|
||||
new Thread(
|
||||
() -> {
|
||||
try {
|
||||
Markdown.render(
|
||||
ctx,
|
||||
response.body().string(),
|
||||
binding.repoFileContents,
|
||||
repository);
|
||||
} catch (IOException e) {
|
||||
requireActivity()
|
||||
.runOnUiThread(
|
||||
() -> {
|
||||
Toasty.error(
|
||||
ctx,
|
||||
ctx
|
||||
.getString(
|
||||
R
|
||||
.string
|
||||
.genericError));
|
||||
binding
|
||||
.fileContentsFrameHeader
|
||||
.setVisibility(
|
||||
View
|
||||
.GONE);
|
||||
binding
|
||||
.fileContentsFrame
|
||||
.setVisibility(
|
||||
View
|
||||
.GONE);
|
||||
});
|
||||
}
|
||||
})
|
||||
.start();
|
||||
break;
|
||||
|
||||
case 200:
|
||||
assert response.body() != null;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Markdown.render(ctx, response.body().string(), binding.repoFileContents, repository);
|
||||
}
|
||||
catch(IOException e) {
|
||||
requireActivity().runOnUiThread(() -> {
|
||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||
binding.fileContentsFrameHeader.setVisibility(View.GONE);
|
||||
binding.fileContentsFrame.setVisibility(View.GONE);
|
||||
});
|
||||
}
|
||||
}).start();
|
||||
break;
|
||||
case 401:
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
||||
break;
|
||||
|
||||
case 401:
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx);
|
||||
break;
|
||||
case 403:
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
binding.fileContentsFrameHeader.setVisibility(View.GONE);
|
||||
binding.fileContentsFrame.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
case 403:
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
binding.fileContentsFrameHeader.setVisibility(View.GONE);
|
||||
binding.fileContentsFrame.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
case 404:
|
||||
binding.fileContentsFrameHeader.setVisibility(View.GONE);
|
||||
binding.fileContentsFrame.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
default:
|
||||
Toasty.error(getContext(), getString(R.string.genericError));
|
||||
binding.fileContentsFrameHeader.setVisibility(View.GONE);
|
||||
binding.fileContentsFrame.setVisibility(View.GONE);
|
||||
break;
|
||||
case 404:
|
||||
binding.fileContentsFrameHeader.setVisibility(View.GONE);
|
||||
binding.fileContentsFrame.setVisibility(View.GONE);
|
||||
break;
|
||||
|
||||
default:
|
||||
Toasty.error(getContext(), getString(R.string.genericError));
|
||||
binding.fileContentsFrameHeader.setVisibility(View.GONE);
|
||||
binding.fileContentsFrame.setVisibility(View.GONE);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
|
||||
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
||||
}
|
||||
});
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
|
||||
Toasty.error(ctx, ctx.getString(R.string.genericServerResponseError));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ public class DetailFragment extends Fragment {
|
|||
|
||||
Call<User> call = RetrofitClient.getApiInterface(context).userGet(username);
|
||||
|
||||
call.enqueue(new Callback<>() {
|
||||
call.enqueue(
|
||||
new Callback<>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(
|
||||
|
@ -92,7 +93,7 @@ public class DetailFragment extends Fragment {
|
|||
? response.body().getEmail()
|
||||
: "";
|
||||
|
||||
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||
int imgRadius = AppUtil.getPixelsFromDensity(context, 3);
|
||||
|
||||
binding.userFullName.setText(username);
|
||||
binding.userLogin.setText(
|
||||
|
@ -147,9 +148,15 @@ public class DetailFragment extends Fragment {
|
|||
public void onError(Exception e) {}
|
||||
});
|
||||
|
||||
binding.userJoinedOn.setText(TimeHelper.formatTime(response.body().getCreated(), locale));
|
||||
binding.userJoinedOn.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(response.body().getCreated()), context));
|
||||
break;
|
||||
binding.userJoinedOn.setText(
|
||||
TimeHelper.formatTime(
|
||||
response.body().getCreated(), locale));
|
||||
binding.userJoinedOn.setOnClickListener(
|
||||
new ClickListener(
|
||||
TimeHelper.customDateFormatForToastDateFormat(
|
||||
response.body().getCreated()),
|
||||
context));
|
||||
break;
|
||||
|
||||
case 401:
|
||||
AlertDialogs.authorizationTokenRevokedDialog(context);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.mian.gitnex.helpers;
|
||||
|
||||
import org.ocpsoft.prettytime.PrettyTime;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
@ -9,7 +8,6 @@ import java.time.format.DateTimeFormatter;
|
|||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import org.mian.gitnex.R;
|
||||
import org.ocpsoft.prettytime.PrettyTime;
|
||||
|
||||
/**
|
||||
|
@ -37,7 +35,7 @@ public class TimeHelper {
|
|||
|
||||
public static String formatTime(Date date, Locale locale) {
|
||||
|
||||
if(date != null) {
|
||||
if (date != null) {
|
||||
PrettyTime prettyTime = new PrettyTime(locale);
|
||||
return prettyTime.format(date);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue