diff --git a/app/build.gradle b/app/build.gradle index aabbedae..6d79b9d5 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -56,10 +56,10 @@ dependencies { def lifecycle_version = '2.5.1' def markwon_version = '4.6.2' def work_version = "2.7.1" - def acra = '5.8.4' + def acra = '5.9.6' implementation fileTree(include: ['*.jar'], dir: 'libs') - implementation 'androidx.appcompat:appcompat:1.5.0' + implementation 'androidx.appcompat:appcompat:1.5.1' implementation 'com.google.android.material:material:1.6.1' implementation 'androidx.compose.material3:material3:1.0.0-alpha15' implementation 'androidx.compose.material3:material3-window-size-class:1.0.0-alpha15' @@ -71,7 +71,7 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.3' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' implementation 'com.squareup.okhttp3:okhttp:5.0.0-alpha.2' - implementation "com.google.code.gson:gson:2.9.0" + implementation 'com.google.code.gson:gson:2.9.1' implementation "com.squareup.picasso:picasso:2.71828" implementation 'jp.wasabeef:picasso-transformations:2.4.0' implementation 'jp.co.cyberagent.android:gpuimage:2.1.0' diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index cf005e48..deb90e81 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -169,6 +169,10 @@ android:name=".activities.CodeEditorActivity" android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|keyboard|keyboardHidden|navigation" android:windowSoftInputMode="adjustResize"/> + finish()); + + if (getIntent().getStringExtra("action") != null) { + action = getIntent().getStringExtra("action"); + } else { + action = ""; + } + + binding.close.setOnClickListener(close -> finish()); + binding.toolbarTitle.setMovementMethod(new ScrollingMovementMethod()); + + if (action.equalsIgnoreCase("edit")) { + + noteId = getIntent().getIntExtra("noteId", 0); + notes = notesApi.fetchNoteById(noteId); + binding.noteContent.setText(notes.getContent()); + + binding.markdownPreview.setVisibility(View.GONE); + binding.toolbarTitle.setText(R.string.editNote); + + binding.noteContent.addTextChangedListener( + new TextWatcher() { + + @Override + public void afterTextChanged(Editable s) { + + String text = binding.noteContent.getText().toString(); + + if (!text.isEmpty()) { + + updateNote(text); + } + } + + @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")) { + + binding.markdownPreview.setVisibility(View.GONE); + + binding.noteContent.addTextChangedListener( + new TextWatcher() { + + @Override + public void afterTextChanged(Editable s) { + + String text = binding.noteContent.getText().toString(); + + if (!text.isEmpty() && text.length() > 4) { + + if (noteId > 0) { + updateNote(text); + } 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 onTextChanged( + CharSequence s, int start, int before, int count) {} + }); + } else { + binding.markdownPreview.setVisibility(View.VISIBLE); + } + } + + private void updateNote(String content) { + notesApi.updateNote(content, Instant.now().getEpochSecond(), noteId); + } + + @Override + public boolean onCreateOptionsMenu(@NonNull Menu menu) { + + MenuInflater inflater = getMenuInflater(); + inflater.inflate(R.menu.markdown_switcher, menu); + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + int id = item.getItemId(); + + if (id == android.R.id.home) { + + finish(); + return true; + } else if (id == R.id.markdown) { + + if (action.equalsIgnoreCase("edit") || action.equalsIgnoreCase("add")) { + if (!renderMd) { + Markdown.render( + ctx, + EmojiParser.parseToUnicode( + Objects.requireNonNull( + binding.noteContent.getText().toString())), + binding.markdownPreview); + + binding.markdownPreview.setVisibility(View.VISIBLE); + binding.noteContent.setVisibility(View.GONE); + renderMd = true; + } else { + binding.markdownPreview.setVisibility(View.GONE); + binding.noteContent.setVisibility(View.VISIBLE); + renderMd = false; + } + } + + return true; + } else { + return super.onOptionsItemSelected(item); + } + } +} diff --git a/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java b/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java index 3c65beb7..88d4fce6 100644 --- a/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/IssueDetailActivity.java @@ -67,7 +67,6 @@ import org.mian.gitnex.helpers.LabelWidthCalculator; import org.mian.gitnex.helpers.Markdown; import org.mian.gitnex.helpers.RoundedTransformation; import org.mian.gitnex.helpers.TimeHelper; -import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Toasty; import org.mian.gitnex.helpers.contexts.IssueContext; import org.mian.gitnex.structs.BottomSheetListener; @@ -774,9 +773,7 @@ public class IssueDetailActivity extends BaseActivity } } - TinyDB tinyDb = TinyDB.getInstance(appCtx); final Locale locale = getResources().getConfiguration().locale; - final String timeFormat = tinyDb.getString("dateFormat", "pretty"); issueCreator = issue.getIssue().getUser().getLogin(); PicassoService.getInstance(ctx) @@ -945,22 +942,14 @@ public class IssueDetailActivity extends BaseActivity if (issue.getIssue().getDueDate() != null) { viewBinding.dueDateFrame.setVisibility(View.VISIBLE); - if (timeFormat.equals("normal") || timeFormat.equals("pretty")) { - - 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 if (timeFormat.equals("normal1")) { - - DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", locale); - String dueDate = formatter.format(issue.getIssue().getDueDate()); - viewBinding.issueDueDate.setText(dueDate); - } + 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.dueDateFrame.setVisibility(View.GONE); @@ -983,18 +972,14 @@ public class IssueDetailActivity extends BaseActivity viewBinding.issueModified.setVisibility(View.INVISIBLE); } - viewBinding.issueCreatedTime.setText( - TimeHelper.formatTime(issue.getIssue().getCreatedAt(), locale, timeFormat, ctx)); viewBinding.issueCreatedTime.setVisibility(View.VISIBLE); - - if (timeFormat.equals("pretty")) { - - 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); diff --git a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java index 4b934554..6ba5cd85 100644 --- a/app/src/main/java/org/mian/gitnex/activities/MainActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/MainActivity.java @@ -46,6 +46,7 @@ import org.mian.gitnex.fragments.MostVisitedReposFragment; import org.mian.gitnex.fragments.MyIssuesFragment; import org.mian.gitnex.fragments.MyProfileFragment; import org.mian.gitnex.fragments.MyRepositoriesFragment; +import org.mian.gitnex.fragments.NotesFragment; import org.mian.gitnex.fragments.NotificationsFragment; import org.mian.gitnex.fragments.OrganizationsFragment; import org.mian.gitnex.fragments.RepositoriesFragment; @@ -143,6 +144,8 @@ 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) { + toolbarTitle.setText(getResources().getString(R.string.navNotes)); } else if (fragmentById instanceof DraftsFragment) { toolbarTitle.setText(getResources().getString(R.string.titleDrafts)); } else if (fragmentById instanceof AdministrationFragment) { @@ -490,6 +493,14 @@ public class MainActivity extends BaseActivity .commit(); navigationView.setCheckedItem(R.id.nav_most_visited); break; + case 10: + toolbarTitle.setText(getResources().getString(R.string.navNotes)); + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.fragment_container, new NotesFragment()) + .commit(); + navigationView.setCheckedItem(R.id.nav_notes); + break; default: toolbarTitle.setText(getResources().getString(R.string.navMyRepos)); @@ -708,6 +719,13 @@ public class MainActivity extends BaseActivity .beginTransaction() .replace(R.id.fragment_container, new MostVisitedReposFragment()) .commit(); + } else if (id == R.id.nav_notes) { + + toolbarTitle.setText(getResources().getString(R.string.navNotes)); + getSupportFragmentManager() + .beginTransaction() + .replace(R.id.fragment_container, new NotesFragment()) + .commit(); } drawer.closeDrawer(GravityCompat.START); diff --git a/app/src/main/java/org/mian/gitnex/activities/SettingsAppearanceActivity.java b/app/src/main/java/org/mian/gitnex/activities/SettingsAppearanceActivity.java index 7580fb47..14714352 100644 --- a/app/src/main/java/org/mian/gitnex/activities/SettingsAppearanceActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/SettingsAppearanceActivity.java @@ -24,8 +24,6 @@ import org.mian.gitnex.helpers.Toasty; */ public class SettingsAppearanceActivity extends BaseActivity { - private static String[] timeList; - private static int timeSelectedChoice = 0; private static String[] customFontList; private static int customFontSelectedChoice = 0; private static String[] themeList; @@ -43,7 +41,6 @@ public class SettingsAppearanceActivity extends BaseActivity { ImageView closeActivity = activitySettingsAppearanceBinding.close; - LinearLayout timeFrame = activitySettingsAppearanceBinding.timeFrame; LinearLayout customFontFrame = activitySettingsAppearanceBinding.customFontFrame; LinearLayout themeFrame = activitySettingsAppearanceBinding.themeSelectionFrame; LinearLayout lightTimeFrame = @@ -52,7 +49,6 @@ public class SettingsAppearanceActivity extends BaseActivity { SwitchMaterial counterBadgesSwitch = activitySettingsAppearanceBinding.switchCounterBadge; - timeList = getResources().getStringArray(R.array.timeFormats); customFontList = getResources().getStringArray(R.array.fonts); themeList = getResources().getStringArray(R.array.themes); @@ -77,7 +73,6 @@ public class SettingsAppearanceActivity extends BaseActivity { darkHour = "0" + darkHour; } - timeSelectedChoice = tinyDB.getInt("timeId"); customFontSelectedChoice = tinyDB.getInt("customFontId", 1); themeSelectedChoice = tinyDB.getInt("themeId", 6); // use system theme as default @@ -87,7 +82,6 @@ public class SettingsAppearanceActivity extends BaseActivity { activitySettingsAppearanceBinding.darkThemeSelectedTime.setText( ctx.getResources() .getString(R.string.settingsThemeTimeSelectedHint, darkHour, darkMinute)); - activitySettingsAppearanceBinding.tvDateTimeSelected.setText(timeList[timeSelectedChoice]); activitySettingsAppearanceBinding.customFontSelected.setText( customFontList[customFontSelectedChoice]); activitySettingsAppearanceBinding.themeSelected.setText(themeList[themeSelectedChoice]); @@ -196,41 +190,6 @@ public class SettingsAppearanceActivity extends BaseActivity { materialAlertDialogBuilder.create().show(); }); - - // time and date dialog - timeFrame.setOnClickListener( - view -> { - MaterialAlertDialogBuilder materialAlertDialogBuilder = - new MaterialAlertDialogBuilder(ctx) - .setTitle(R.string.settingsTimeSelectorDialogTitle) - .setCancelable(timeSelectedChoice != -1) - .setSingleChoiceItems( - timeList, - timeSelectedChoice, - (dialogInterfaceTime, i) -> { - timeSelectedChoice = i; - activitySettingsAppearanceBinding.tvDateTimeSelected - .setText(timeList[i]); - tinyDB.putInt("timeId", i); - - switch (i) { - case 0: - tinyDB.putString("dateFormat", "pretty"); - break; - case 1: - tinyDB.putString("dateFormat", "normal"); - break; - } - - dialogInterfaceTime.dismiss(); - Toasty.success( - appCtx, - getResources() - .getString(R.string.settingsSave)); - }); - - materialAlertDialogBuilder.create().show(); - }); } private void initCloseListener() { diff --git a/app/src/main/java/org/mian/gitnex/activities/SettingsGeneralActivity.java b/app/src/main/java/org/mian/gitnex/activities/SettingsGeneralActivity.java index b86f11d4..1c99b114 100644 --- a/app/src/main/java/org/mian/gitnex/activities/SettingsGeneralActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/SettingsGeneralActivity.java @@ -90,6 +90,9 @@ public class SettingsGeneralActivity extends BaseActivity { viewBinding.homeScreenSelected.setText( getResources().getString(R.string.navMostVisited)); + } else if (homeScreenSelectedChoice == 10) { + + viewBinding.homeScreenSelected.setText(getResources().getString(R.string.navNotes)); } viewBinding.homeScreenFrame.setOnClickListener( diff --git a/app/src/main/java/org/mian/gitnex/activities/WikiActivity.java b/app/src/main/java/org/mian/gitnex/activities/WikiActivity.java index f7109966..b9542393 100644 --- a/app/src/main/java/org/mian/gitnex/activities/WikiActivity.java +++ b/app/src/main/java/org/mian/gitnex/activities/WikiActivity.java @@ -395,7 +395,7 @@ public class WikiActivity extends BaseActivity implements BottomSheetListener { } @Override - public boolean onCreateOptionsMenu(Menu menu) { + public boolean onCreateOptionsMenu(@NonNull Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.markdown_switcher, menu); diff --git a/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java index aee87bcd..72e605aa 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/AdminCronTasksAdapter.java @@ -18,7 +18,6 @@ import org.mian.gitnex.R; import org.mian.gitnex.clients.RetrofitClient; import org.mian.gitnex.helpers.AlertDialogs; import org.mian.gitnex.helpers.TimeHelper; -import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Toasty; import retrofit2.Call; import retrofit2.Callback; @@ -43,7 +42,6 @@ public class AdminCronTasksAdapter Context ctx = itemView.getContext(); final Locale locale = ctx.getResources().getConfiguration().locale; - final String timeFormat = TinyDB.getInstance(ctx).getString("dateFormat", "pretty"); ImageView runTask = itemView.findViewById(R.id.runTask); taskName = itemView.findViewById(R.id.taskName); @@ -56,14 +54,10 @@ public class AdminCronTasksAdapter String lastRun = ""; if (cronTasks.getNext() != null) { - nextRun = - TimeHelper.formatTime( - cronTasks.getNext(), locale, timeFormat, ctx); + nextRun = TimeHelper.formatTime(cronTasks.getNext(), locale); } if (cronTasks.getPrev() != null) { - lastRun = - TimeHelper.formatTime( - cronTasks.getPrev(), locale, timeFormat, ctx); + lastRun = TimeHelper.formatTime(cronTasks.getPrev(), locale); } View view = @@ -127,7 +121,7 @@ public class AdminCronTasksAdapter Call call = RetrofitClient.getApiInterface(ctx).adminCronRun(taskName); call.enqueue( - new Callback() { + new Callback<>() { @Override public void onResponse( diff --git a/app/src/main/java/org/mian/gitnex/adapters/AdminGetUsersAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/AdminGetUsersAdapter.java index 731a0b86..a4c2ff77 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/AdminGetUsersAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/AdminGetUsersAdapter.java @@ -135,7 +135,6 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter - TimeHelper.customDateFormatForToastDateFormat( - issueComment.getCreatedAt())); - } else if (timeFormat.equals("normal")) { - infoBuilder = - new StringBuilder( - TimeHelper.formatTime( - issueComment.getCreatedAt(), - locale, - "normal", - context)); - } + infoBuilder = + new StringBuilder( + TimeHelper.formatTime(issueComment.getCreatedAt(), locale)); + + information.setOnClickListener( + new ClickListener( + TimeHelper.customDateFormatForToastDateFormat( + issueComment.getCreatedAt()), + context)); if (!issueComment.getCreatedAt().equals(issueComment.getUpdatedAt())) { - if (infoBuilder != null) { - infoBuilder - .append(context.getString(R.string.colorfulBulletSpan)) - .append(context.getString(R.string.modifiedText)); - } + infoBuilder + .append(context.getString(R.string.colorfulBulletSpan)) + .append(context.getString(R.string.modifiedText)); } } String info = infoBuilder.toString(); diff --git a/app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java index e0902080..15febc26 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/IssuesAdapter.java @@ -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,7 +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 org.ocpsoft.prettytime.PrettyTime; /** * @author M M Arif @@ -169,7 +166,6 @@ public class IssuesAdapter extends RecyclerView.Adapter void bindData(Issue issue) { Locale locale = context.getResources().getConfiguration().locale; - String timeFormat = tinyDb.getString("dateFormat", "pretty"); int imgRadius = AppUtil.getPixelsFromDensity(context, 3); @@ -294,46 +290,11 @@ public class IssuesAdapter extends RecyclerView.Adapter context.getResources().getColor(R.color.releasePre, null)); } - switch (timeFormat) { - case "pretty": - { - PrettyTime prettyTime = new PrettyTime(locale); - String createdTime = prettyTime.format(issue.getCreatedAt()); - this.issueCreatedTime.setText(createdTime); - this.issueCreatedTime.setOnClickListener( - new ClickListener( - TimeHelper.customDateFormatForToastDateFormat( - issue.getCreatedAt()), - context)); - break; - } - case "normal": - { - DateFormat formatter = - new SimpleDateFormat( - "yyyy-MM-dd '" - + context.getResources() - .getString(R.string.timeAtText) - + "' HH:mm", - locale); - String createdTime = formatter.format(issue.getCreatedAt()); - this.issueCreatedTime.setText(createdTime); - break; - } - case "normal1": - { - DateFormat formatter = - new SimpleDateFormat( - "dd-MM-yyyy '" - + context.getResources() - .getString(R.string.timeAtText) - + "' HH:mm", - locale); - String createdTime = formatter.format(issue.getCreatedAt()); - this.issueCreatedTime.setText(createdTime); - break; - } - } + this.issueCreatedTime.setText(TimeHelper.formatTime(issue.getCreatedAt(), locale)); + this.issueCreatedTime.setOnClickListener( + new ClickListener( + TimeHelper.customDateFormatForToastDateFormat(issue.getCreatedAt()), + context)); } } } diff --git a/app/src/main/java/org/mian/gitnex/adapters/MilestonesAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/MilestonesAdapter.java index 9087246c..1cf19c05 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/MilestonesAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/MilestonesAdapter.java @@ -25,7 +25,6 @@ import org.mian.gitnex.activities.RepoDetailActivity; import org.mian.gitnex.helpers.ClickListener; import org.mian.gitnex.helpers.Markdown; import org.mian.gitnex.helpers.TimeHelper; -import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.contexts.RepositoryContext; /** @@ -188,9 +187,7 @@ public class MilestonesAdapter extends RecyclerView.Adapter { + + private List notesList; + private final Context ctx; + private final Intent noteIntent; + + public NotesAdapter(Context ctx, List notesListMain) { + this.ctx = ctx; + this.notesList = notesListMain; + noteIntent = new Intent(ctx, CreateNoteActivity.class); + } + + class NotesViewHolder extends RecyclerView.ViewHolder { + + private Notes notes; + + private final TextView content; + private final TextView datetime; + + private NotesViewHolder(View itemView) { + + super(itemView); + + content = itemView.findViewById(R.id.content); + 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); + }); + + deleteNote.setOnClickListener( + itemDelete -> { + 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(); + }); + } + } + + private void deleteNote(int position, int noteId) { + + NotesApi notesApi = BaseApi.getInstance(ctx, NotesApi.class); + assert notesApi != null; + notesApi.deleteNote(noteId); + notesList.remove(position); + notifyItemRemoved(position); + notifyItemRangeChanged(position, notesList.size()); + 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); + return new NotesViewHolder(v); + } + + @Override + public void onBindViewHolder(@NonNull NotesAdapter.NotesViewHolder holder, int position) { + + Locale locale = ctx.getResources().getConfiguration().locale; + Notes currentItem = notesList.get(position); + holder.notes = currentItem; + + 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)); + } + } + + @Override + public int getItemCount() { + return notesList.size(); + } + + @SuppressLint("NotifyDataSetChanged") + public void notifyDataChanged() { + notifyDataSetChanged(); + } + + public void updateList(List list) { + + notesList = list; + notifyDataChanged(); + } +} diff --git a/app/src/main/java/org/mian/gitnex/adapters/PullRequestsAdapter.java b/app/src/main/java/org/mian/gitnex/adapters/PullRequestsAdapter.java index 61cdefc7..516b334c 100644 --- a/app/src/main/java/org/mian/gitnex/adapters/PullRequestsAdapter.java +++ b/app/src/main/java/org/mian/gitnex/adapters/PullRequestsAdapter.java @@ -175,12 +175,10 @@ public class PullRequestsAdapter extends RecyclerView.Adapter 15) { commentIcon.setImageDrawable( @@ -299,13 +296,11 @@ public class PullRequestsAdapter extends RecyclerView.Adapter 0) { - String firstCharacter = String.valueOf(wikiPageMetaData.getTitle().charAt(0)); + 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); - avatar.setImageDrawable(drawable); - } else { - avatar.setVisibility(View.GONE); - } + 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()) { wikiMenu.setVisibility(View.GONE); diff --git a/app/src/main/java/org/mian/gitnex/core/MainApplication.java b/app/src/main/java/org/mian/gitnex/core/MainApplication.java index 9b70a466..1ec6e47c 100644 --- a/app/src/main/java/org/mian/gitnex/core/MainApplication.java +++ b/app/src/main/java/org/mian/gitnex/core/MainApplication.java @@ -52,7 +52,7 @@ public class MainApplication extends Application { if (tinyDB.getBoolean("crashReportingEnabled", true)) { - CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(this); + CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(); ACRABuilder.withBuildConfigClass(BuildConfig.class) .withReportContent( @@ -62,23 +62,28 @@ public class MainApplication extends Application { ReportField.AVAILABLE_MEM_SIZE, ReportField.BRAND) .setReportFormat(StringFormat.KEY_VALUE_LIST); - ACRABuilder.getPluginConfigurationBuilder(NotificationConfigurationBuilder.class) - .withResTitle(R.string.crashTitle) - .withResIcon(R.drawable.gitnex_transparent) - .withResChannelName(R.string.setCrashReports) - .withResText(R.string.crashMessage) - .withEnabled(true); - ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class) - .withMailTo(getResources().getString(R.string.appEmail)) - .withSubject( - getResources() - .getString( - R.string.crashReportEmailSubject, - AppUtil.getAppBuildNo(context))) - .withReportAsFile(true) - .withEnabled(true); - ACRABuilder.getPluginConfigurationBuilder(LimiterConfigurationBuilder.class) - .setEnabled(true); + + 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 LimiterConfigurationBuilder().withEnabled(true).build()); ACRA.init(this, ACRABuilder); } diff --git a/app/src/main/java/org/mian/gitnex/database/api/NotesApi.java b/app/src/main/java/org/mian/gitnex/database/api/NotesApi.java new file mode 100644 index 00000000..f6ad2046 --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/database/api/NotesApi.java @@ -0,0 +1,61 @@ +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; + +/** + * @author M M Arif + */ +public class NotesApi extends BaseApi { + + private final NotesDao notesDao; + + NotesApi(Context context) { + super(context); + notesDao = gitnexDatabase.notesDao(); + } + + public long insertNote(String content, Integer datetime) { + + Notes notes = new Notes(); + notes.setContent(content); + notes.setDatetime(datetime); + + return insertNoteAsyncTask(notes); + } + + public long insertNoteAsyncTask(Notes notes) { + return notesDao.insertNote(notes); + } + + public LiveData> fetchAllNotes() { + return notesDao.fetchAllNotes(); + } + + public Notes fetchNoteById(int noteId) { + return notesDao.fetchNoteById(noteId); + } + + public Integer fetchNotesCount() { + return notesDao.fetchNotesCount(); + } + + public void updateNote(final String content, final long modified, int noteId) { + executorService.execute(() -> notesDao.updateNote(content, modified, noteId)); + } + + public void deleteAllNotes() { + executorService.execute(notesDao::deleteAllNotes); + } + + public void deleteNote(final int noteId) { + final Notes note = notesDao.fetchNoteById(noteId); + + if (note != null) { + executorService.execute(() -> notesDao.deleteNote(noteId)); + } + } +} diff --git a/app/src/main/java/org/mian/gitnex/database/dao/NotesDao.java b/app/src/main/java/org/mian/gitnex/database/dao/NotesDao.java new file mode 100644 index 00000000..6433faa0 --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/database/dao/NotesDao.java @@ -0,0 +1,36 @@ +package org.mian.gitnex.database.dao; + +import androidx.lifecycle.LiveData; +import androidx.room.Dao; +import androidx.room.Insert; +import androidx.room.Query; +import java.util.List; +import org.mian.gitnex.database.models.Notes; + +/** + * @author M M Arif + */ +@Dao +public interface NotesDao { + + @Insert + long insertNote(Notes notes); + + @Query("SELECT * FROM Notes ORDER BY modified DESC, noteId DESC") + LiveData> fetchAllNotes(); + + @Query("SELECT * FROM Notes WHERE noteId = :noteId") + Notes fetchNoteById(int noteId); + + @Query("SELECT count(noteId) FROM Notes") + Integer fetchNotesCount(); + + @Query("UPDATE Notes SET content = :content, modified = :modified WHERE noteId = :noteId") + void updateNote(String content, long modified, int noteId); + + @Query("DELETE FROM Notes") + void deleteAllNotes(); + + @Query("DELETE FROM Notes WHERE noteId = :noteId") + void deleteNote(int noteId); +} diff --git a/app/src/main/java/org/mian/gitnex/database/db/GitnexDatabase.java b/app/src/main/java/org/mian/gitnex/database/db/GitnexDatabase.java index f0dd225f..cac62fd3 100644 --- a/app/src/main/java/org/mian/gitnex/database/db/GitnexDatabase.java +++ b/app/src/main/java/org/mian/gitnex/database/db/GitnexDatabase.java @@ -8,9 +8,11 @@ import androidx.room.RoomDatabase; import androidx.room.migration.Migration; import androidx.sqlite.db.SupportSQLiteDatabase; import org.mian.gitnex.database.dao.DraftsDao; +import org.mian.gitnex.database.dao.NotesDao; import org.mian.gitnex.database.dao.RepositoriesDao; import org.mian.gitnex.database.dao.UserAccountsDao; import org.mian.gitnex.database.models.Draft; +import org.mian.gitnex.database.models.Notes; import org.mian.gitnex.database.models.Repository; import org.mian.gitnex.database.models.UserAccount; @@ -18,8 +20,8 @@ import org.mian.gitnex.database.models.UserAccount; * @author M M Arif */ @Database( - entities = {Draft.class, Repository.class, UserAccount.class}, - version = 6, + entities = {Draft.class, Repository.class, UserAccount.class, Notes.class}, + version = 7, exportSchema = false) public abstract class GitnexDatabase extends RoomDatabase { @@ -68,6 +70,15 @@ public abstract class GitnexDatabase extends RoomDatabase { "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'))"); + } + }; private static volatile GitnexDatabase gitnexDatabase; public static GitnexDatabase getDatabaseInstance(Context context) { @@ -85,7 +96,8 @@ public abstract class GitnexDatabase extends RoomDatabase { MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, - MIGRATION_5_6) + MIGRATION_5_6, + MIGRATION_6_7) .build(); } } @@ -99,4 +111,6 @@ public abstract class GitnexDatabase extends RoomDatabase { public abstract RepositoriesDao repositoriesDao(); public abstract UserAccountsDao userAccountsDao(); + + public abstract NotesDao notesDao(); } diff --git a/app/src/main/java/org/mian/gitnex/database/models/Notes.java b/app/src/main/java/org/mian/gitnex/database/models/Notes.java new file mode 100644 index 00000000..41f6e6ac --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/database/models/Notes.java @@ -0,0 +1,52 @@ +package org.mian.gitnex.database.models; + +import androidx.annotation.Nullable; +import androidx.room.Entity; +import androidx.room.PrimaryKey; +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; + private Integer datetime; + private Integer modified; + + public int getNoteId() { + return noteId; + } + + public void setNoteId(int noteId) { + this.noteId = noteId; + } + + @Nullable public String getContent() { + return content; + } + + public void setContent(@Nullable String content) { + this.content = content; + } + + public Integer getDatetime() { + return datetime; + } + + public void setDatetime(Integer datetime) { + this.datetime = datetime; + } + + public Integer getModified() { + return modified; + } + + public void setModified(Integer modified) { + this.modified = modified; + } +} diff --git a/app/src/main/java/org/mian/gitnex/fragments/CommitDetailFragment.java b/app/src/main/java/org/mian/gitnex/fragments/CommitDetailFragment.java index c23073ea..9d4b3785 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/CommitDetailFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/CommitDetailFragment.java @@ -229,9 +229,7 @@ public class CommitDetailFragment extends Fragment { .getDate()), getResources() .getConfiguration() - .locale, - "pretty", - requireContext())), + .locale)), HtmlCompat.FROM_HTML_MODE_COMPACT)); } else { binding.commitAuthorAndCommitter.setText( @@ -250,9 +248,7 @@ public class CommitDetailFragment extends Fragment { .getDate()), getResources() .getConfiguration() - .locale, - "pretty", - requireContext())), + .locale)), HtmlCompat.FROM_HTML_MODE_COMPACT)); } diff --git a/app/src/main/java/org/mian/gitnex/fragments/NotesFragment.java b/app/src/main/java/org/mian/gitnex/fragments/NotesFragment.java new file mode 100644 index 00000000..ec1fa73c --- /dev/null +++ b/app/src/main/java/org/mian/gitnex/fragments/NotesFragment.java @@ -0,0 +1,206 @@ +package org.mian.gitnex.fragments; + +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; +import android.view.MenuItem; +import android.view.View; +import android.view.ViewGroup; +import android.view.inputmethod.EditorInfo; +import androidx.annotation.NonNull; +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; +import org.mian.gitnex.adapters.NotesAdapter; +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.FragmentNotesBinding; +import org.mian.gitnex.helpers.Toasty; + +/** + * @author M M Arif + */ +public class NotesFragment extends Fragment { + + private FragmentNotesBinding binding; + private Context ctx; + private NotesAdapter adapter; + private NotesApi notesApi; + private List notesList; + private Intent noteIntent; + + @Override + public View onCreateView( + @NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + + binding = FragmentNotesBinding.inflate(inflater, container, false); + + ctx = getContext(); + setHasOptionsMenu(true); + + ((MainActivity) requireActivity()) + .setActionBarTitle(getResources().getString(R.string.navNotes)); + + noteIntent = new Intent(ctx, CreateNoteActivity.class); + + binding.newNote.setOnClickListener( + view -> { + noteIntent.putExtra("action", "add"); + ctx.startActivity(noteIntent); + }); + + notesList = new ArrayList<>(); + notesApi = BaseApi.getInstance(ctx, NotesApi.class); + + binding.recyclerView.setHasFixedSize(true); + binding.recyclerView.setLayoutManager(new LinearLayoutManager(ctx)); + + binding.recyclerView.setPadding(0, 0, 0, 220); + binding.recyclerView.setClipToPadding(false); + + adapter = new NotesAdapter(ctx, notesList); + + binding.pullToRefresh.setOnRefreshListener( + () -> + new Handler(Looper.getMainLooper()) + .postDelayed( + () -> { + notesList.clear(); + binding.pullToRefresh.setRefreshing(false); + binding.progressBar.setVisibility(View.VISIBLE); + fetchDataAsync(); + }, + 250)); + + fetchDataAsync(); + + return binding.getRoot(); + } + + @Override + public void onResume() { + super.onResume(); + fetchDataAsync(); + } + + private void fetchDataAsync() { + + notesApi.fetchAllNotes() + .observe( + getViewLifecycleOwner(), + allNotes -> { + binding.pullToRefresh.setRefreshing(false); + assert allNotes != null; + if (allNotes.size() > 0) { + + notesList.clear(); + binding.noData.setVisibility(View.GONE); + notesList.addAll(allNotes); + adapter.notifyDataChanged(); + binding.recyclerView.setAdapter(adapter); + } else { + + binding.noData.setVisibility(View.VISIBLE); + } + binding.progressBar.setVisibility(View.GONE); + }); + } + + private void filter(String text) { + + List arr = new ArrayList<>(); + + for (Notes d : notesList) { + + if (d == null || d.getContent() == null) { + continue; + } + + if (d.getContent().toLowerCase().contains(text)) { + arr.add(d); + } + } + + adapter.updateList(arr); + } + + public void deleteAllNotes() { + + if (notesList.size() > 0) { + + notesApi.deleteAllNotes(); + notesList.clear(); + adapter.notifyDataChanged(); + Toasty.success( + ctx, ctx.getResources().getQuantityString(R.plurals.noteDeleteMessage, 2)); + } else { + Toasty.warning(ctx, getResources().getString(R.string.noDataFound)); + } + } + + @Override + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { + + inflater.inflate(R.menu.reset_menu, menu); + inflater.inflate(R.menu.search_menu, menu); + super.onCreateOptionsMenu(menu, inflater); + + MenuItem searchItem = menu.findItem(R.id.action_search); + SearchView searchView = (SearchView) searchItem.getActionView(); + searchView.setImeOptions(EditorInfo.IME_ACTION_DONE); + + searchView.setOnQueryTextListener( + new SearchView.OnQueryTextListener() { + + @Override + public boolean onQueryTextSubmit(String query) { + + return false; + } + + @Override + public boolean onQueryTextChange(String newText) { + + filter(newText); + return false; + } + }); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + if (item.getItemId() == R.id.reset_menu_item) { + + 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(); + } + } + + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java b/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java index e8ed1828..975fb496 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/RepoInfoFragment.java @@ -32,7 +32,6 @@ import org.mian.gitnex.helpers.AppUtil; import org.mian.gitnex.helpers.ClickListener; import org.mian.gitnex.helpers.Markdown; import org.mian.gitnex.helpers.TimeHelper; -import org.mian.gitnex.helpers.TinyDB; import org.mian.gitnex.helpers.Toasty; import org.mian.gitnex.helpers.contexts.RepositoryContext; import retrofit2.Call; @@ -70,7 +69,6 @@ public class RepoInfoFragment extends Fragment { @NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { binding = FragmentRepoInfoBinding.inflate(inflater, container, false); - TinyDB tinyDb = TinyDB.getInstance(getContext()); ctx = getContext(); Locale locale = getResources().getConfiguration().locale; @@ -79,7 +77,7 @@ public class RepoInfoFragment extends Fragment { binding.repoMetaFrame.setVisibility(View.GONE); - setRepoInfo(locale, tinyDb.getString("dateFormat", "pretty")); + setRepoInfo(locale); if (isExpandViewVisible()) { toggleExpandView(); @@ -147,7 +145,7 @@ public class RepoInfoFragment extends Fragment { return binding.repoMetaFrame.getVisibility() == View.VISIBLE; } - private void setRepoInfo(Locale locale, final String timeFormat) { + private void setRepoInfo(Locale locale) { Repository repoInfo = repository.getRepository(); if (isAdded()) { @@ -208,17 +206,13 @@ public class RepoInfoFragment extends Fragment { FileUtils.byteCountToDisplaySize(repoInfo.getSize() * 1024)); binding.repoMetaCreatedAt.setText( - TimeHelper.formatTime(repoInfo.getCreatedAt(), locale, timeFormat, ctx)); - if (timeFormat.equals("pretty")) { - binding.repoMetaCreatedAt.setOnClickListener( - new ClickListener( - TimeHelper.customDateFormatForToastDateFormat( - repoInfo.getCreatedAt()), - ctx)); - } + TimeHelper.formatTime(repoInfo.getCreatedAt(), locale)); + binding.repoMetaCreatedAt.setOnClickListener( + new ClickListener( + TimeHelper.customDateFormatForToastDateFormat(repoInfo.getCreatedAt()), + ctx)); - String repoMetaUpdatedAt = - TimeHelper.formatTime(repoInfo.getUpdatedAt(), locale, timeFormat, ctx); + String repoMetaUpdatedAt = TimeHelper.formatTime(repoInfo.getUpdatedAt(), locale); String website = (repoInfo.getWebsite().isEmpty()) diff --git a/app/src/main/java/org/mian/gitnex/fragments/profile/DetailFragment.java b/app/src/main/java/org/mian/gitnex/fragments/profile/DetailFragment.java index ac3f3ca1..cf569d35 100644 --- a/app/src/main/java/org/mian/gitnex/fragments/profile/DetailFragment.java +++ b/app/src/main/java/org/mian/gitnex/fragments/profile/DetailFragment.java @@ -74,7 +74,7 @@ public class DetailFragment extends Fragment { Call call = RetrofitClient.getApiInterface(context).userGet(username); call.enqueue( - new Callback() { + new Callback<>() { @Override public void onResponse( @@ -94,7 +94,6 @@ public class DetailFragment extends Fragment { : ""; int imgRadius = AppUtil.getPixelsFromDensity(context, 3); - String timeFormat = tinyDb.getString("dateFormat", "pretty"); binding.userFullName.setText(username); binding.userLogin.setText( @@ -151,19 +150,12 @@ public class DetailFragment extends Fragment { binding.userJoinedOn.setText( TimeHelper.formatTime( - response.body().getCreated(), - locale, - timeFormat, + response.body().getCreated(), locale)); + binding.userJoinedOn.setOnClickListener( + new ClickListener( + TimeHelper.customDateFormatForToastDateFormat( + response.body().getCreated()), context)); - if (timeFormat.equals("pretty")) { - binding.userJoinedOn.setOnClickListener( - new ClickListener( - TimeHelper - .customDateFormatForToastDateFormat( - response.body() - .getCreated()), - context)); - } break; case 401: diff --git a/app/src/main/java/org/mian/gitnex/helpers/TimeHelper.java b/app/src/main/java/org/mian/gitnex/helpers/TimeHelper.java index 1fdac369..0cdab2aa 100644 --- a/app/src/main/java/org/mian/gitnex/helpers/TimeHelper.java +++ b/app/src/main/java/org/mian/gitnex/helpers/TimeHelper.java @@ -1,6 +1,5 @@ package org.mian.gitnex.helpers; -import android.content.Context; 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; /** @@ -35,38 +33,11 @@ public class TimeHelper { return customDateFormatForToastDateFormat(createdTime); } - public static String formatTime(Date date, Locale locale, String timeFormat, Context context) { + public static String formatTime(Date date, Locale locale) { if (date != null) { - switch (timeFormat) { - case "pretty": - { - PrettyTime prettyTime = new PrettyTime(locale); - return prettyTime.format(date); - } - case "normal": - { - DateFormat formatter = - new SimpleDateFormat( - "yyyy-MM-dd '" - + context.getResources() - .getString(R.string.timeAtText) - + "' HH:mm", - locale); - return formatter.format(date); - } - case "normal1": - { - DateFormat formatter = - new SimpleDateFormat( - "dd-MM-yyyy '" - + context.getResources() - .getString(R.string.timeAtText) - + "' HH:mm", - locale); - return formatter.format(date); - } - } + PrettyTime prettyTime = new PrettyTime(locale); + return prettyTime.format(date); } return ""; diff --git a/app/src/main/res/drawable/ic_notes.xml b/app/src/main/res/drawable/ic_notes.xml new file mode 100644 index 00000000..0d627d72 --- /dev/null +++ b/app/src/main/res/drawable/ic_notes.xml @@ -0,0 +1,34 @@ + + + + + + diff --git a/app/src/main/res/layout/activity_create_note.xml b/app/src/main/res/layout/activity_create_note.xml new file mode 100644 index 00000000..c568b4ce --- /dev/null +++ b/app/src/main/res/layout/activity_create_note.xml @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_settings_appearance.xml b/app/src/main/res/layout/activity_settings_appearance.xml index dfe2d646..c398f61f 100644 --- a/app/src/main/res/layout/activity_settings_appearance.xml +++ b/app/src/main/res/layout/activity_settings_appearance.xml @@ -180,39 +180,6 @@ - - - - - - - - + android:layout_marginBottom="@dimen/dimen6dp" + android:padding="@dimen/dimen16dp"> + app:srcCompat="@drawable/ic_people" /> @@ -41,11 +42,11 @@ android:id="@+id/adminUsers" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingStart="12dp" - android:paddingEnd="12dp" + android:paddingStart="@dimen/dimen12dp" + android:paddingEnd="@dimen/dimen12dp" android:text="@string/adminUsers" android:textColor="?attr/primaryTextColor" - android:textSize="16sp"/> + android:textSize="@dimen/dimen16sp" /> @@ -53,16 +54,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/generalImgContentText" - app:srcCompat="@drawable/ic_chevron_right"/> + app:srcCompat="@drawable/ic_chevron_right" /> - - + android:layout_marginBottom="@dimen/dimen6dp" + android:padding="@dimen/dimen16dp"> + app:srcCompat="@drawable/ic_tasks" /> @@ -90,11 +86,11 @@ android:id="@+id/adminCron" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingStart="12dp" - android:paddingEnd="12dp" + android:paddingStart="@dimen/dimen12dp" + android:paddingEnd="@dimen/dimen12dp" android:text="@string/adminCron" android:textColor="?attr/primaryTextColor" - android:textSize="16sp"/> + android:textSize="@dimen/dimen16sp" /> @@ -102,15 +98,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/generalImgContentText" - app:srcCompat="@drawable/ic_chevron_right"/> + app:srcCompat="@drawable/ic_chevron_right" /> - - + android:layout_marginBottom="@dimen/dimen6dp" + android:padding="@dimen/dimen16dp"> + app:srcCompat="@drawable/ic_directory" /> @@ -138,11 +130,11 @@ android:id="@+id/unadoptedRepos" android:layout_width="match_parent" android:layout_height="wrap_content" - android:paddingStart="12dp" - android:paddingEnd="12dp" + android:paddingStart="@dimen/dimen12dp" + android:paddingEnd="@dimen/dimen12dp" android:text="@string/unadoptedRepos" android:textColor="?attr/primaryTextColor" - android:textSize="16sp"/> + android:textSize="@dimen/dimen16sp" /> @@ -150,7 +142,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:contentDescription="@string/generalImgContentText" - app:srcCompat="@drawable/ic_chevron_right"/> + app:srcCompat="@drawable/ic_chevron_right" /> diff --git a/app/src/main/res/layout/fragment_notes.xml b/app/src/main/res/layout/fragment_notes.xml new file mode 100644 index 00000000..ceffa19c --- /dev/null +++ b/app/src/main/res/layout/fragment_notes.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/list_most_visited_repos.xml b/app/src/main/res/layout/list_most_visited_repos.xml index 705bf547..600747e7 100644 --- a/app/src/main/res/layout/list_most_visited_repos.xml +++ b/app/src/main/res/layout/list_most_visited_repos.xml @@ -97,7 +97,7 @@ android:gravity="center_vertical|end" android:orientation="horizontal" android:paddingStart="@dimen/dimen6dp" - android:paddingEnd="@dimen/dimen6dp"> + android:paddingEnd="@dimen/dimen0dp"> + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/drawer_menu.xml b/app/src/main/res/menu/drawer_menu.xml index 3a61c3b1..8340a5b5 100644 --- a/app/src/main/res/menu/drawer_menu.xml +++ b/app/src/main/res/menu/drawer_menu.xml @@ -42,6 +42,10 @@ android:icon="@drawable/ic_trending" android:title="@string/navMostVisited"/> + + diff --git a/app/src/main/res/values/settings.xml b/app/src/main/res/values/settings.xml index fe858ea7..6ba4e45b 100644 --- a/app/src/main/res/values/settings.xml +++ b/app/src/main/res/values/settings.xml @@ -20,11 +20,6 @@ uk - - @string/settingsDateTimeHeaderDefault - @string/settingsDateTimeNormal - - Roboto Manrope @@ -63,6 +58,7 @@ @string/pageTitleNotifications @string/navMyIssues @string/navMostVisited + @string/navNotes diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 06d41a27..0f6cd6ce 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,6 +32,7 @@ Administration My Issues Most Visited Repos + Notes @@ -199,13 +200,10 @@ Delete Trusted Certificates Delete Trusted Certificates? Are you sure to delete any manually trusted certificate or hostname? \n\nYou will also be logged out. - Date & Time Settings saved Language English Appearance - Pretty - Normal Choose Language Light Theme Switch Time Dark Theme Switch Time @@ -791,6 +789,19 @@ Code Editor Open in Code Editor + + New Note + Edit Note + Start taking your notes here + Created %s + Updated %s + Do you really want to delete this note? + + Note deleted successfully + Notes deleted successfully + + This will delete all of your notes. This action cannot be undone. + commit %1$s added %2$s %3$s