Compare commits

...

53 Commits

Author SHA1 Message Date
dc6b1bb5b6 Release 3.1.0 RC2 (#653)
Release 3.1.0 RC2

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/653
2020-08-19 09:07:12 +02:00
8768c87b8a Update missing progress bars (#652)
update missing progress bars

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/652
2020-08-18 19:55:34 +02:00
7caff70946 Edit and delete a file (#626)
update if file is modified on resume

implementation of edit file

Merge branch 'master' into 44-delete-file

Merge branch '44-delete-file' of codeberg.org:gitnex/GitNex into 44-delete-file

Merge branch 'master' into 44-delete-file

# Conflicts:
#	app/src/main/java/org/mian/gitnex/activities/CreateFileActivity.java
#	app/src/main/java/org/mian/gitnex/activities/FileViewActivity.java
#	app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java
#	app/src/main/java/org/mian/gitnex/fragments/BottomSheetFileViewerFragment.java

Merge branch 'master' into 44-delete-file

implement delete file

add links to bottomsheet

Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/626
2020-08-18 16:37:10 +02:00
76137c56bc Improve drafts ui, add edited comments, create new ones on each call (#628)
Merge branch 'master' into 627-save-edit-draft

# Conflicts:
#	app/src/main/java/org/mian/gitnex/actions/IssueActions.java

Merge branch 'master' into 627-save-edit-draft

Improve drafts, add edited comments, create new ones on each call.

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/628
2020-08-18 16:11:31 +02:00
dcacf1f141 Design Accounts from Nav menu (#648)
Merge branch 'master' into new-account-design

Merge branch 'master' into new-account-design

enhance the dialog UI

Merge branch 'master' into new-account-design

New account design in nav with dialog popup list

New design for accounts accessing

Co-authored-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/648
2020-08-18 16:10:46 +02:00
7585eb4834 Update bug icon (#651)
update bug icon

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/651
2020-08-17 19:08:29 +02:00
7dd231ee95 Set notifications as home srceen (#644) 2020-08-12 09:31:39 +02:00
d5fd6d8cc4 Fix share issue url (#643) 2020-08-12 09:31:06 +02:00
28963bb079 Using language instead of country. (#647)
Using language instead of country.

Co-authored-by: opyale <opyale@noreply.gitea.io>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/647
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-08-11 18:32:30 +02:00
87649ebae8 Introduce new progress indicators (#638)
Add indicator to the rest of fragments/activities

Merge branch 'master' into profress-indicators

# Conflicts:
#	app/src/main/res/layout/activity_credits.xml
#	app/src/main/res/layout/activity_sponsors.xml

wip to remove old indicator

Make dark green as primary color, clean up app files

Introduce new progress indicators

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/638
2020-08-09 10:23:51 +02:00
a92969a47f Fix jumps in drawer when open for all items(icons, user data) (#639)
Fix drawer jumps when open for all items

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/639
2020-08-09 10:23:19 +02:00
d9cd04facf Layout improvements (#637)
Layout improvements

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/637
2020-08-08 17:43:14 +02:00
3eacfe91fe 3.1.0 RC1 release (#636)
3.1.0 RC1 release

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/636
2020-08-07 17:28:39 +02:00
e38d141d38 Quick labels, assignes dialog ui fixes (#635)
labels, assignes dialog ui fixes

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/635
2020-08-07 17:23:04 +02:00
7c40c049d4 Fix email login loop (can login with email again) (#629)
Merge branch 'master' into fix-email-logins

# Conflicts:
#	app/src/main/java/org/mian/gitnex/activities/LoginActivity.java

cleanup

Fix emails logins loop

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/629
2020-08-06 17:31:31 +02:00
b4b7981722 Open respective content when tap on repo info prs, watchers, forks, stargazers (#632)
Merge branch 'master' into open-repo-info-item

Open respective content when tap on repo info items, prs, watchers, forks, stargazers

Co-authored-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/632
2020-08-06 17:19:37 +02:00
96fad2d73e Copy urls (#631)
fix url open in browser

Copy org and repo url

Copy urls

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/631
2020-08-06 17:18:02 +02:00
24064192e4 Enhance dialog buttons (#633)
switch to outline buttons

Enhance and fix color scheme for dialogs

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/633
2020-08-06 17:17:27 +02:00
12a7b6040b App wide UI changes and refactors (#630)
Enhance and update the buttons across the app, colorful animation on tap

update toasty in view models

update toasty in fragments

update toasty in actions, activities, adapters

Alert dialogs buttons arrangements

strings fixes

switch to fab buttons

remove snackbar

Enhance whole app UI, bring consistency among the elements

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/630
2020-08-06 17:16:51 +02:00
30921ea330 Multiple accounts support (#624)
Title update

Color clean up

switch to another account and update the token at login

Add new account

Add fab button for new account and activity

update libs

Remove account from Manage accounts list

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/624
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-08-04 22:50:04 +02:00
ea36a3f6d6 Repository forks (#606)
Repository forks

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/606
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-29 21:46:58 +02:00
f1ecc42876 Md support in file viewer (#607)
format

implement support for md on tap on icon

show icon for md files only

Add md to top bar

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/607
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-29 20:45:05 +02:00
73e7acfbdf Drop support for login with email (#622)
Drop support for login with email

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/622
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-29 20:28:24 +02:00
a9ad91d954 Fix drafts from notifications view (#618)
Fix drafts when coming from notifications

Fix star/watchers layout

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/618
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-29 20:04:40 +02:00
ff537b79ff BasicAuth Login: Handle existing token (#611)
fix code comment

bugfix

code format

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/611
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-29 16:27:47 +02:00
7efc8650fa Remove unlock for public repos (#605)
Remove unlock for public repos

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/605
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-26 12:01:15 +02:00
a171abc0b8 Official start of 3.1.0 development (#603)
Official start of 3.1.0 development

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/603
2020-07-23 20:17:38 +02:00
0928e936d7 Prepare release (#599)
update  feature list in readme

Merge branch 'master' into 480-update-screenshots

update desc for f-droid

update screenshots, add changelogs

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/599
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-23 19:35:46 +02:00
a29011c6a2 Crowdin 2020-07-23 (#602)
Crowdin Update

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/602
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-23 18:38:18 +02:00
c09fc4988a Support Samsung DeX (#601)
Support Samsung DeX

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/601
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-23 18:37:32 +02:00
39ac49b258 Notifications (#554)
Cleanup

Extending and improving notifications

Using new icons instead

Lowering polling delay to one minute and other improvements

Fixing minor issues

Simplifying progress layout

Fixing bugs and other improvements

Adding translations

Notifications

Co-authored-by: opyale <opyale@noreply.gitea.io>
Co-authored-by: 6543 <6543@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/554
Reviewed-by: 6543 <6543@noreply.codeberg.org>
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-22 21:32:42 +02:00
cd55f946f0 Crowdin 2020-07-22 (#597)
Crowdin Update

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/597
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-22 14:48:12 +02:00
b529f81115 Fix some bugs (#596)
remove redundant casting

Fix edittext layout when typing(reduce size), fix refresh drafts. Minor improvements

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/596
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-19 15:44:08 +02:00
e6109ef36d Search drafts (#574)
Merge branch 'master' into search-drafts

Merge branch 'master' into search-drafts

Merge branch 'master' into search-drafts

Merge branch 'master' into search-drafts

Merge branch 'master' into search-drafts

Merge branch 'master' into search-drafts

Merge branch 'master' into search-drafts

Merge branch 'master' into search-drafts

Merge branch 'master' into search-drafts

# Conflicts:
#	app/src/main/java/org/mian/gitnex/fragments/DraftsFragment.java

search drafts

Co-authored-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/574
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-19 12:33:58 +02:00
e00fcd846a Add missed icons and improve the ratio of all icons across the app (#592)
Merge branch 'master' into new-missing-icons

Merge branch 'master' into new-missing-icons

Fix background and icon

Fix search bar icons and layout to match the themes

new lines?

Merge branch 'master' into new-missing-icons

Add missed icons, and improve the ratio of all icons across the app

Co-authored-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/592
2020-07-19 12:24:47 +02:00
060c86c090 Add server avatar to user accounts (#594)
Add server avatar to user accounts

Co-authored-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/594
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-19 12:13:37 +02:00
26f54280a1 Add explore and drafts to set as home screen options (#588)
Fix icon cut off sizes

Add explore and drafts to set as home screen options

Co-authored-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/588
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-19 12:05:08 +02:00
8a7923cba7 Fix VersionCheck (#591)
code dedub

Bugfix & Test Correction

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/591
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-14 18:20:00 +02:00
673b9f564c Crowdin 2020-07-14 (#590)
crowdin_2020-07-14

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/590
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-14 17:14:06 +02:00
d1be03956c Transition of old icons to new ones (#589)
last set of updates and changes to the icons

Add more icons

WIP : transition of more icons

Switch of icons to new icons for the whole app - WIP

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/589
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-12 19:18:50 +02:00
caa437d5e3 Switch branches (#571)
Fix default branch

Merge branch 'master' into switch-branches

# Conflicts:
#	app/src/main/res/layout/bottom_sheet_repo.xml
#	app/src/main/res/values/strings.xml

update icon

Merge branch 'master' into switch-branches

Merge branch 'master' into switch-branches

update the missing parts

Minor updates

Merge branch 'master' into switch-branches

Merge branch 'master' into switch-branches

# Conflicts:
#	app/src/main/java/org/mian/gitnex/activities/CreateIssueActivity.java
#	app/src/main/java/org/mian/gitnex/activities/RepoDetailActivity.java
#	app/src/main/java/org/mian/gitnex/fragments/BottomSheetRepoFragment.java
#	app/src/main/java/org/mian/gitnex/fragments/FilesFragment.java

Add branch to breadcrumb and dir structure fix

Make change branch work

clean up

Merge branch 'master' into switch-branches

add icon in top bar, add interface listener

Merge branch 'master' into switch-branches

Merge remote-tracking branch 'remotes/main/master' into switch-branches

# Conflicts:
#	app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
#	app/src/main/java/org/mian/gitnex/fragments/ProfileFragment.java
#	app/src/main/java/org/mian/gitnex/helpers/PathsHelper.java

Switching between branches.

Minor fixes

Merge remote-tracking branch 'remotes/main/master' into login-fix

URL parsing, label and other improvements.

Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@noreply.codeberg.org>
Co-authored-by: opyale <opyale@noreply.gitea.io>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/571
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-12 17:14:50 +02:00
25036ce5d2 Remove Unused Locales (#585)
Remove Unused Locales

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/585
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-11 12:49:35 +02:00
a8a34ccc7a New icons (#587)
repo info icons update

Update icons across the app

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/587
Reviewed-by: 6543 <6543@noreply.codeberg.org>
2020-07-10 22:54:09 +02:00
f87e8020d8 Remove Unused Resources (#586)
Remove Unused Resources

Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/586
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-10 12:43:51 +02:00
4d67e63db4 Fix license (#584)
Fix license

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/584
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-09 17:42:13 +02:00
3561dde19f Badges and drone fix. (#583)
Removing link

Badges and drone fix.

Co-authored-by: opyale <opyale@noreply.gitea.io>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/583
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-09 15:18:21 +02:00
9c48dec54d Delete drafts [settings] (#576)
Merge branch '450-drafts-settings' of codeberg.org:gitnex/GitNex into 450-drafts-settings

Fix package move

Merge branch 'master' into 450-drafts-settings

Merge branch 'master' into 450-drafts-settings

fix default value save

Delete drafts settings

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/576
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-09 13:55:09 +02:00
3d72d68e14 Fixing CI (#582)
Fixing CI

Co-authored-by: opyale <opyale@noreply.gitea.io>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/582
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-09 13:37:44 +02:00
47b24470e6 Improving CI. (#581)
Improving CI.

Co-authored-by: opyale <opyale@noreply.gitea.io>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/581
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-09 13:29:36 +02:00
1db6a3294b Using GitLab CI. (#580)
Using smaller image and publishing releases.

Fixing things.

Merge branch 'gitlab-ci' of https://codeberg.org/opyale/GitNex into gitlab-ci

Removing eclint.

Merge branch 'master' into gitlab-ci

Only run jobs when master changed.

Using GitLab CI.

Co-authored-by: opyale <opyale@noreply.gitea.io>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/580
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-09 08:55:05 +02:00
500dc019c1 Moving TinyDB and AppUtil to helpers. (#579)
Moving TinyDB and AppUtil to helpers.

Co-authored-by: opyale <opyale@noreply.gitea.io>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/579
Reviewed-by: M M Arif <mmarif@noreply.codeberg.org>
2020-07-07 19:15:01 +02:00
e2aff890d7 Accounts overview screen (#577)
optimize url string

Overview of accounts in the app

Co-authored-by: M M Arif <mmarif@swatian.com>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/577
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-07 16:20:43 +02:00
cdfc2cfb9e Implement drafts, introduce Room persistence library for db (#139)
Fix no draft message

translation updates

format improvements

typo update

some renaming refactors

Use better naming convention

remove duplicate source

arrange draft titles

enhance click listener area

Launch drafts from reply screen and clean up

Add message draft saved

update repositories tasks

Update user accounts repository with thread, remove async tasks

remove async task in drafts

update layout, change async to thread in drafts

Merge branch 'master' into pull_139

# Conflicts:
#	app/build.gradle
#	app/src/main/java/org/mian/gitnex/activities/LoginActivity.java

Merge branch 'master' into pull_139

# Conflicts:
#	app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java

Merge branch 'pull_139' of codeberg.org:gitnex/GitNex into pull_139

# Conflicts:
#	app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java

Merge branch 'master' into pull_139

# Conflicts:
#	app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
#	app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
#	app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java

Merge branch 'master' into pull_139

Merge branch 'master' into pull_139

Merge branch 'master' into pull_139 and fix conflicts

# Conflicts:
#	app/build.gradle
#	app/src/main/java/org/mian/gitnex/activities/LoginActivity.java
#	app/src/main/java/org/mian/gitnex/activities/MainActivity.java
#	app/src/main/java/org/mian/gitnex/activities/ReplyToIssueActivity.java
#	app/src/main/java/org/mian/gitnex/adapters/MyReposListAdapter.java
#	app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java
#	app/src/main/res/values/strings.xml

Code Format

Merge branch 'master' into 15-comments-draft

Merge branch 'master' into 15-comments-draft

Merge branch 'master' into 15-comments-draft

# Conflicts:
#	app/src/main/java/org/mian/gitnex/activities/MainActivity.java
#	app/src/main/res/values/strings.xml

Go to draft, save on type and other fixes

delete all drafts, added messages where needed

delete draft

Force logout

Merge branch 'master' into 15-comments-draft

Merge branch 'master' into 15-comments-draft

# Conflicts:
#	app/src/main/java/org/mian/gitnex/activities/MainActivity.java
#	app/src/main/java/org/mian/gitnex/helpers/StaticGlobalVariables.java

check if account data is null, we need to log the user out for the 1st time.

Merge branch 'master' into 15-comments-draft

fix repo owner, name sequence

Add comments for test, show drafts list

Add repos to db

Add account to db and other refactors to the code

Merge branch 'master' into 15-comments-draft

Merge branch 'master' into 15-comments-draft

Merge branch 'master' into 15-comments-draft

Merge branch 'master' into 15-comments-draft

# Conflicts:
#	app/build.gradle
#	app/src/main/AndroidManifest.xml

Merge branch 'master' into 15-comments-draft

merge

more queries, added dao repositories, layout update

Added queries in dao

some refactor. added models, dao, entities (accounts, repositories, drafts)

WIP on implementing drafts, introduced Room persistence library for db.

Co-authored-by: M M Arif <mmarif@swatian.com>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://codeberg.org/gitnex/GitNex/pulls/139
Reviewed-by: opyale <opyale@noreply.codeberg.org>
2020-07-04 22:51:55 +02:00
446 changed files with 12251 additions and 5449 deletions

View File

@ -26,6 +26,12 @@ steps:
# depends_on: [ clone ]
# commands:
# - /opt/intellij/bin/idea.sh inspect/format ...
#
# - name: do-or-check-formatting
# image: dlsniper/docker-intellij
# depends_on: [ clone ]
# commands:
# - /opt/intellij/bin/idea.sh format -s .idea/codeStyles/Project.xml -m *.java app/src/main/java
trigger:
event:
@ -65,7 +71,7 @@ steps:
- name: sign
image: nextcloudci/android:android-49
environment:
TOKEN:
BOT_TOKEN:
from_secret: BOT_TOKEN
KS_PASS:
from_secret: KS_PASS
@ -88,7 +94,7 @@ steps:
PLUGIN_FILE: 'signed.apk'
PLUGIN_TIMEOUT: 180
PLUGIN_ATTEMPTS: 5
PLUGIN_DESTINATION: 'https://cloud.swatian.com/remote.php/dav/files/GitNexBot/GitNex-Builds/latest.apk'
PLUGIN_DESTINATION: 'https://cloud.swatian.com/remote.php/dav/files/GitNexBot/gitnex/builds/latest.apk'
PLUGIN_CUSTOM_ARGUMENTS: '--progress-bar'
trigger:

View File

@ -9,7 +9,6 @@ max_line_length = 150
[*.java]
indent_style = tab
max_line_length = 220
line_comment = //
block_comment_start = /*
block_comment = *

63
.gitlab-ci.yml Normal file
View File

@ -0,0 +1,63 @@
stages:
- test
- build
- sign
- publish
test:
image: nextcloudci/android:android-49
stage: test
script:
- ./gradlew test
build:
image: nextcloudci/android:android-49
stage: build
only:
- master
script:
- ./gradlew build
artifacts:
paths:
- app/build/outputs/
expire_in: 15 minutes
sign:
image: nextcloudci/android:android-49
stage: sign
only:
- master
variables:
OUTPUT: "signed.apk"
GITEA: "https://gitea.com"
KS_FILE: "ci_keystore.jks"
script:
- ./scripts/sign-build.sh
artifacts:
paths:
- signed.apk
expire_in: 15 minutes
latest:
image: tutum/curl
stage: publish
only:
- master
variables:
WEBDAV_USERNAME: "GitNexBot"
PLUGIN_FILE: "signed.apk"
PLUGIN_DESTINATION: "https://cloud.swatian.com/remote.php/dav/files/GitNexBot/gitnex/builds/latest.apk"
script:
- curl -T "$PLUGIN_FILE" -u "$WEBDAV_USERNAME":"$WEBDAV_PASSWORD" "$PLUGIN_DESTINATION"
release:
image: tutum/curl
stage: publish
only:
- tags
variables:
WEBDAV_USERNAME: "GitNexBot"
PLUGIN_FILE: "signed.apk"
script:
- "[[ $CI_COMMIT_REF_NAME == *'-rc'* ]] && echo 'Upload blocked. Build seems to be a release candidate.' && exit 0"
- curl -T "$PLUGIN_FILE" -u "$WEBDAV_USERNAME":"$WEBDAV_PASSWORD" 'https://cloud.swatian.com/remote.php/dav/files/GitNexBot/gitnex/releases/'"$CI_COMMIT_REF_NAME"'.apk'

View File

@ -29,6 +29,7 @@
<option name="ELSE_ON_NEW_LINE" value="true" />
<option name="CATCH_ON_NEW_LINE" value="true" />
<option name="FINALLY_ON_NEW_LINE" value="true" />
<option name="ALIGN_MULTILINE_PARAMETERS" value="false" />
<option name="SPACE_BEFORE_IF_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_WHILE_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_FOR_PARENTHESES" value="false" />
@ -36,9 +37,13 @@
<option name="SPACE_BEFORE_CATCH_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_SWITCH_PARENTHESES" value="false" />
<option name="SPACE_BEFORE_SYNCHRONIZED_PARENTHESES" value="false" />
<option name="CALL_PARAMETERS_WRAP" value="1" />
<option name="METHOD_PARAMETERS_WRAP" value="1" />
<option name="THROWS_LIST_WRAP" value="1" />
<option name="METHOD_CALL_CHAIN_WRAP" value="1" />
<option name="TERNARY_OPERATION_WRAP" value="1" />
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
<option name="IF_BRACE_FORCE" value="3" />
<option name="WRAP_ON_TYPING" value="1" />
<indentOptions>
<option name="USE_TAB_CHARACTER" value="true" />
<option name="SMART_TABS" value="true" />

63
LICENSE
View File

@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
@ -620,55 +620,18 @@ copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
GitNex is an Android client/application for Gitea.
Copyright (C) 2019 The GitNex Authors
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Mastalab is a Mastodon client for Android devices
Copyright (C) 2017 Thomas Schneider
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Also add information on how to contact you by electronic and paper mail.
If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:
Mastalab Copyright (C) 2017 Thomas Schneider
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, your program's commands
might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.

View File

@ -11,9 +11,7 @@ GitNex is licensed under GPLv3 License. See the LICENSE file for the full licens
## Downloads
[<img alt='Get it on F-droid' src='https://gitlab.com/fdroid/artwork/raw/master/badge/get-it-on.png' height="80"/>](https://f-droid.org/en/packages/org.mian.gitnex/)
[<img alt='Get it on Google Play' src='https://play.google.com/intl/en_us/badges/images/generic/en_badge_web_generic.png' height="80"/>](https://play.google.com/store/apps/details?id=org.mian.gitnex)
[<img alt='Download APK' src='https://gitnex.com/img/download-apk.png' height="80"/>](https://cloud.swatian.com/s/QoDFzMxmnf2FfYw)
Download latest build from master: [https://cloud.swatian.com/s/Cq592xGEfnsGAAW](https://cloud.swatian.com/s/Cq592xGEfnsGAAW)
[<img alt='Download builds and releases' src='assets/apk-badge.png' height="82"/>](https://cloud.swatian.com/s/DN7E5xxtaw4fRbE)
## Note about Gitea version
Please make sure that you are on latest stable release or later for better app experience.
@ -26,12 +24,15 @@ Option 1 - Download the source code, open it in Android Studio and build it ther
Option 2 - Open terminal(Linux) and cd to the project dir. Run `./gradlew build`.
## Features
- Repositories / issues/ org list
- File and directory browser
- File viewer
- Create files
- Explore repositories
- Issues list
- Pull requests
- Merge pull request
- Files diff for PRs
- Notifications
- Drafts
- [MANY MORE](https://codeberg.org/gitnex/GitNex/wiki/Features)
## Contributing

View File

@ -6,12 +6,12 @@ android {
applicationId "org.mian.gitnex"
minSdkVersion 21
targetSdkVersion 29
versionCode 297
versionName "3.0.0-rc3"
versionCode 308
versionName "3.1.0-rc2"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
viewBinding {
enabled = true
buildFeatures {
viewBinding = true
}
buildTypes {
release {
@ -36,13 +36,14 @@ configurations {
}
dependencies {
def lifecycle_version = "2.3.0-alpha05"
def markwon_version = '4.4.0'
def lifecycle_version = "2.3.0-alpha06"
def markwon_version = "4.4.0"
def work_version = "2.4.0"
def acra = "5.5.0"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:1.3.0-alpha01"
implementation "com.google.android.material:material:1.3.0-alpha01"
implementation "com.google.android.material:material:1.3.0-alpha02"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
implementation "androidx.legacy:legacy-support-v4:1.0.0"
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
@ -50,14 +51,14 @@ dependencies {
androidTestImplementation "androidx.test:runner:1.2.0"
androidTestImplementation "androidx.test.espresso:espresso-core:3.2.0"
implementation "com.github.vihtarb:tooltip:0.2.0"
implementation 'com.squareup.okhttp3:okhttp:4.7.2'
implementation 'com.squareup.okhttp3:okhttp:4.8.0'
implementation "com.google.code.gson:gson:2.8.6"
implementation "com.squareup.picasso:picasso:2.71828"
implementation "com.amulyakhare:com.amulyakhare.textdrawable:1.0.1"
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.7.2'
implementation 'com.squareup.okhttp3:logging-interceptor:4.8.0'
implementation 'org.ocpsoft.prettytime:prettytime:4.0.5.Final'
implementation "com.vdurmont:emoji-java:5.1.1"
implementation "com.pes.materialcolorpicker:library:1.2.5"
@ -80,11 +81,15 @@ dependencies {
implementation "com.hendraanggrian.appcompat:socialview-commons:0.2"
implementation "com.github.HamidrezaAmz:BreadcrumbsView:0.2.9"
implementation "commons-io:commons-io:20030203.000550"
implementation 'org.apache.commons:commons-lang3:3.11'
implementation "com.github.chrisbanes:PhotoView:2.3.0"
implementation "com.github.barteksc:android-pdf-viewer:3.2.0-beta.1"
implementation "ch.acra:acra-mail:$acra"
implementation "ch.acra:acra-limiter:$acra"
implementation "ch.acra:acra-notification:$acra"
implementation "androidx.room:room-runtime:2.2.5"
annotationProcessor "androidx.room:room-compiler:2.2.5"
implementation "androidx.work:work-runtime:$work_version"
implementation "com.eightbitlab:blurview:1.6.3"
implementation "io.mikael:urlbuilder:2.0.9"

View File

@ -4,6 +4,7 @@
package="org.mian.gitnex">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
@ -11,9 +12,11 @@
android:icon="@mipmap/app_logo"
android:label="@string/app_name"
android:networkSecurityConfig="@xml/network_security_config"
android:resizeableActivity="true"
android:roundIcon="@mipmap/app_logo_round"
android:supportsRtl="true"
tools:targetApi="n">
<activity android:name=".activities.MergePullRequestActivity" />
<activity
android:name=".activities.FileViewActivity"
@ -45,8 +48,6 @@
android:name=".activities.OrganizationDetailActivity"
android:label="@string/title_activity_org_detail"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".activities.SponsorsActivity" />
<activity android:name=".activities.CreditsActivity" />
<activity android:name=".activities.CreateLabelActivity" />
<activity android:name=".activities.CreateIssueActivity" />
<activity android:name=".activities.CreateMilestoneActivity" />
@ -58,7 +59,7 @@
android:name=".activities.RepoDetailActivity"
android:label="@string/title_activity_repo_detail"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".activities.MainActivity" android:theme="@android:style/Theme.NoTitleBar">
<activity android:name=".activities.MainActivity" android:theme="@android:style/Theme.NoTitleBar" android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -80,6 +81,15 @@
<activity android:name=".activities.SettingsTranslationActivity" />
<activity android:name=".activities.SettingsReportsActivity" />
<activity android:name=".activities.AddNewTeamMemberActivity" />
<activity android:name=".activities.SettingsDraftsActivity" />
<activity android:name=".activities.RepoForksActivity" />
<activity android:name=".activities.AddNewAccountActivity" />
<!-- Version < 3.0. DeX Mode and Screen Mirroring support -->
<meta-data android:name="com.samsung.android.keepalive.density" android:value="true"/>
<!-- Version >= 3.0. DeX Dual Mode support -->
<meta-data android:name="com.samsung.android.multidisplay.keep_process_alive" android:value="true"/>
</application>
</manifest>
</manifest>

View File

@ -2,16 +2,16 @@ package org.mian.gitnex.actions;
import android.content.Context;
import android.util.Log;
import androidx.annotation.NonNull;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.AddCollaboratorToRepositoryActivity;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Collaborators;
import org.mian.gitnex.models.Permission;
import org.mian.gitnex.util.TinyDB;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
@ -47,7 +47,7 @@ public class CollaboratorActions {
if(response.isSuccessful()) {
if(response.code() == 204) {
Toasty.info(context, context.getString(R.string.removeCollaboratorToastText));
Toasty.success(context, context.getString(R.string.removeCollaboratorToastText));
((AddCollaboratorToRepositoryActivity)context).finish();
//Log.i("addCollaboratorSearch", addCollaboratorSearch.getText().toString());
//tinyDb.putBoolean("updateDataSet", true);
@ -66,17 +66,17 @@ public class CollaboratorActions {
}
else if(response.code() == 403) {
Toasty.info(context, context.getString(R.string.authorizeError));
Toasty.error(context, context.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(context, context.getString(R.string.apiNotFound));
Toasty.warning(context, context.getString(R.string.apiNotFound));
}
else {
Toasty.info(context, context.getString(R.string.genericError));
Toasty.error(context, context.getString(R.string.genericError));
}
@ -117,7 +117,7 @@ public class CollaboratorActions {
if(response.isSuccessful()) {
if(response.code() == 204) {
Toasty.info(context, context.getString(R.string.addCollaboratorToastText));
Toasty.success(context, context.getString(R.string.addCollaboratorToastText));
((AddCollaboratorToRepositoryActivity)context).finish();
//AddCollaboratorToRepositoryActivity usersSearchData = new AddCollaboratorToRepositoryActivity();
//usersSearchData.loadUserSearchList(instanceUrl, instanceToken, searchKeyword, context);
@ -134,17 +134,17 @@ public class CollaboratorActions {
}
else if(response.code() == 403) {
Toasty.info(context, context.getString(R.string.authorizeError));
Toasty.error(context, context.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(context, context.getString(R.string.apiNotFound));
Toasty.warning(context, context.getString(R.string.apiNotFound));
}
else {
Toasty.info(context, context.getString(R.string.genericError));
Toasty.error(context, context.getString(R.string.genericError));
}

View File

@ -7,12 +7,13 @@ import com.google.gson.JsonElement;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.ReplyToIssueActivity;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.DraftsApi;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.IssueComments;
import org.mian.gitnex.models.UpdateIssueState;
import org.mian.gitnex.util.TinyDB;
import retrofit2.Call;
import retrofit2.Callback;
@ -22,7 +23,7 @@ import retrofit2.Callback;
public class IssueActions {
public static void editIssueComment(final Context ctx, final int commentId, final String commentBody) {
public static void editIssueComment(final Context ctx, final int commentId, final String commentBody, long draftIdOnCreate) {
final TinyDB tinyDb = new TinyDB(ctx);
final String instanceUrl = tinyDb.getString("instanceUrl");
@ -48,6 +49,10 @@ public class IssueActions {
tinyDb.putBoolean("commentEdited", true);
Toasty.info(ctx, ctx.getString(R.string.editCommentUpdatedText));
DraftsApi draftsApi = new DraftsApi(ctx);
draftsApi.deleteSingleDraft((int) draftIdOnCreate);
((ReplyToIssueActivity) ctx).finish();
}
@ -59,17 +64,17 @@ public class IssueActions {
}
else if(response.code() == 403) {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, ctx.getString(R.string.genericError));
Toasty.error(ctx, ctx.getString(R.string.genericError));
}
@ -113,13 +118,13 @@ public class IssueActions {
if(issueState.equals("closed")) {
Toasty.info(ctx, ctx.getString(R.string.issueStateClosed));
Toasty.success(ctx, ctx.getString(R.string.issueStateClosed));
tinyDb.putString("issueState", "closed");
}
else if(issueState.equals("open")) {
Toasty.info(ctx, ctx.getString(R.string.issueStateReopened));
Toasty.success(ctx, ctx.getString(R.string.issueStateReopened));
tinyDb.putString("issueState", "open");
}
@ -133,17 +138,17 @@ public class IssueActions {
}
else if(response.code() == 403) {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, ctx.getString(R.string.genericError));
Toasty.error(ctx, ctx.getString(R.string.genericError));
}
@ -184,14 +189,14 @@ public class IssueActions {
if(response.code() == 201) {
Toasty.info(ctx, ctx.getString(R.string.subscribedSuccessfully));
Toasty.success(ctx, ctx.getString(R.string.subscribedSuccessfully));
tinyDB.putBoolean("issueSubscribed", true);
}
else if(response.code() == 200) {
tinyDB.putBoolean("issueSubscribed", true);
Toasty.info(ctx, ctx.getString(R.string.alreadySubscribed));
Toasty.success(ctx, ctx.getString(R.string.alreadySubscribed));
}
@ -203,7 +208,7 @@ public class IssueActions {
}
else {
Toasty.info(ctx, ctx.getString(R.string.subscriptionError));
Toasty.error(ctx, ctx.getString(R.string.subscriptionError));
}
@ -212,7 +217,7 @@ public class IssueActions {
@Override
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
Toasty.info(ctx, ctx.getString(R.string.unsubscribedSuccessfully));
Toasty.success(ctx, ctx.getString(R.string.unsubscribedSuccessfully));
}
});
@ -244,14 +249,14 @@ public class IssueActions {
if(response.code() == 201) {
Toasty.info(ctx, ctx.getString(R.string.unsubscribedSuccessfully));
Toasty.success(ctx, ctx.getString(R.string.unsubscribedSuccessfully));
tinyDB.putBoolean("issueSubscribed", false);
}
else if(response.code() == 200) {
tinyDB.putBoolean("issueSubscribed", false);
Toasty.info(ctx, ctx.getString(R.string.alreadyUnsubscribed));
Toasty.success(ctx, ctx.getString(R.string.alreadyUnsubscribed));
}
@ -263,7 +268,7 @@ public class IssueActions {
}
else {
Toasty.info(ctx, ctx.getString(R.string.unsubscriptionError));
Toasty.error(ctx, ctx.getString(R.string.unsubscriptionError));
}
@ -272,7 +277,7 @@ public class IssueActions {
@Override
public void onFailure(@NonNull Call<Void> call, @NonNull Throwable t) {
Toasty.info(ctx, ctx.getString(R.string.unsubscriptionError));
Toasty.error(ctx, ctx.getString(R.string.unsubscriptionError));
}
});
}

View File

@ -7,9 +7,9 @@ import com.google.gson.JsonElement;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Milestones;
import org.mian.gitnex.util.TinyDB;
import retrofit2.Call;
import retrofit2.Callback;
@ -48,7 +48,7 @@ public class MilestoneActions {
if(response.isSuccessful()) {
Toasty.info(ctx, ctx.getString(R.string.milestoneStatusUpdate));
Toasty.success(ctx, ctx.getString(R.string.milestoneStatusUpdate));
}
else if(response.code() == 401) {
@ -61,7 +61,7 @@ public class MilestoneActions {
}
else {
Toasty.info(ctx, ctx.getString(R.string.genericError));
Toasty.error(ctx, ctx.getString(R.string.genericError));
}
@ -106,7 +106,7 @@ public class MilestoneActions {
if(response.isSuccessful()) {
Toasty.info(ctx, ctx.getString(R.string.milestoneStatusUpdate));
Toasty.success(ctx, ctx.getString(R.string.milestoneStatusUpdate));
}
else if(response.code() == 401) {
@ -119,7 +119,7 @@ public class MilestoneActions {
}
else {
Toasty.info(ctx, ctx.getString(R.string.genericError));
Toasty.error(ctx, ctx.getString(R.string.genericError));
}

View File

@ -0,0 +1,59 @@
package org.mian.gitnex.actions;
import android.content.Context;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.NotificationThread;
import java.io.IOException;
import java.util.Date;
import okhttp3.ResponseBody;
import retrofit2.Call;
/**
* Author opyale
*/
public class NotificationsActions {
public enum NotificationStatus {READ, UNREAD, PINNED}
private TinyDB tinyDB;
private Context context;
private String instanceUrl;
private String instanceToken;
public NotificationsActions(Context context) {
this.context = context;
this.tinyDB = new TinyDB(context);
String loginUid = tinyDB.getString("loginUid");
instanceUrl = tinyDB.getString("instanceUrl");
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
}
public void setNotificationStatus(NotificationThread notificationThread, NotificationStatus notificationStatus) throws IOException {
Call<ResponseBody> call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface()
.markNotificationThreadAsRead(instanceToken, notificationThread.getId(), notificationStatus.name());
if(!call.execute().isSuccessful()) {
throw new IllegalStateException();
}
}
public boolean setAllNotificationsRead(Date date) throws IOException {
Call<ResponseBody> call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface()
.markNotificationThreadsAsRead(instanceToken, AppUtil.getTimestampFromDate(context, date), true,
new String[]{"unread", "pinned"}, "read");
return call.execute().isSuccessful();
}
}

View File

@ -8,8 +8,8 @@ import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.util.TinyDB;
import retrofit2.Call;
import retrofit2.Callback;
@ -46,7 +46,7 @@ public class RepositoryActions {
if(response.code() == 204) {
tinyDb.putBoolean("repoCreated", true);
Toasty.info(context, context.getString(R.string.starRepositorySuccess));
Toasty.success(context, context.getString(R.string.starRepositorySuccess));
}
}
@ -60,17 +60,17 @@ public class RepositoryActions {
}
else if(response.code() == 403) {
Toasty.info(context, context.getString(R.string.authorizeError));
Toasty.error(context, context.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(context, context.getString(R.string.apiNotFound));
Toasty.warning(context, context.getString(R.string.apiNotFound));
}
else {
Toasty.info(context, context.getString(R.string.genericError));
Toasty.error(context, context.getString(R.string.genericError));
}
@ -111,7 +111,7 @@ public class RepositoryActions {
if(response.code() == 204) {
tinyDb.putBoolean("repoCreated", true);
Toasty.info(context, context.getString(R.string.unStarRepositorySuccess));
Toasty.success(context, context.getString(R.string.unStarRepositorySuccess));
}
}
@ -125,17 +125,17 @@ public class RepositoryActions {
}
else if(response.code() == 403) {
Toasty.info(context, context.getString(R.string.authorizeError));
Toasty.error(context, context.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(context, context.getString(R.string.apiNotFound));
Toasty.warning(context, context.getString(R.string.apiNotFound));
}
else {
Toasty.info(context, context.getString(R.string.genericError));
Toasty.error(context, context.getString(R.string.genericError));
}
@ -176,7 +176,7 @@ public class RepositoryActions {
if(response.code() == 200) {
tinyDb.putBoolean("repoCreated", true);
Toasty.info(context, context.getString(R.string.watchRepositorySuccess));
Toasty.success(context, context.getString(R.string.watchRepositorySuccess));
}
}
@ -190,17 +190,17 @@ public class RepositoryActions {
}
else if(response.code() == 403) {
Toasty.info(context, context.getString(R.string.authorizeError));
Toasty.error(context, context.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(context, context.getString(R.string.apiNotFound));
Toasty.warning(context, context.getString(R.string.apiNotFound));
}
else {
Toasty.info(context, context.getString(R.string.genericError));
Toasty.error(context, context.getString(R.string.genericError));
}
@ -240,7 +240,7 @@ public class RepositoryActions {
if(response.code() == 204) {
tinyDb.putBoolean("repoCreated", true);
Toasty.info(context, context.getString(R.string.unWatchRepositorySuccess));
Toasty.success(context, context.getString(R.string.unWatchRepositorySuccess));
}
else if(response.code() == 401) {
@ -253,17 +253,17 @@ public class RepositoryActions {
}
else if(response.code() == 403) {
Toasty.info(context, context.getString(R.string.authorizeError));
Toasty.error(context, context.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(context, context.getString(R.string.apiNotFound));
Toasty.warning(context, context.getString(R.string.apiNotFound));
}
else {
Toasty.info(context, context.getString(R.string.genericError));
Toasty.error(context, context.getString(R.string.genericError));
}

View File

@ -8,8 +8,8 @@ import org.mian.gitnex.activities.AddNewTeamMemberActivity;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.util.TinyDB;
import retrofit2.Call;
import retrofit2.Callback;
@ -43,7 +43,7 @@ public class TeamActions {
if(response.code() == 204) {
tinyDb.putBoolean("teamActionFlag", true);
Toasty.info(context, context.getString(R.string.memberRemovedMessage));
Toasty.success(context, context.getString(R.string.memberRemovedMessage));
((AddNewTeamMemberActivity)context).finish();
}
@ -59,17 +59,17 @@ public class TeamActions {
}
else if(response.code() == 403) {
Toasty.info(context, context.getString(R.string.authorizeError));
Toasty.error(context, context.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(context, context.getString(R.string.apiNotFound));
Toasty.warning(context, context.getString(R.string.apiNotFound));
}
else {
Toasty.info(context, context.getString(R.string.genericError));
Toasty.error(context, context.getString(R.string.genericError));
}
@ -109,7 +109,7 @@ public class TeamActions {
if(response.code() == 204) {
tinyDb.putBoolean("teamActionFlag", true);
Toasty.info(context, context.getString(R.string.memberAddedMessage));
Toasty.success(context, context.getString(R.string.memberAddedMessage));
((AddNewTeamMemberActivity)context).finish();
}
@ -125,17 +125,17 @@ public class TeamActions {
}
else if(response.code() == 403) {
Toasty.info(context, context.getString(R.string.authorizeError));
Toasty.error(context, context.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(context, context.getString(R.string.apiNotFound));
Toasty.warning(context, context.getString(R.string.apiNotFound));
}
else {
Toasty.info(context, context.getString(R.string.genericError));
Toasty.error(context, context.getString(R.string.genericError));
}

View File

@ -1,30 +1,29 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.UserSearchAdapter;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.models.UserSearch;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.models.UserSearch;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif

View File

@ -0,0 +1,267 @@
package org.mian.gitnex.activities;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.databinding.ActivityAddNewAccountBinding;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.PathsHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.UrlHelper;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.GiteaVersion;
import org.mian.gitnex.models.UserInfo;
import java.net.URI;
import io.mikael.urlbuilder.UrlBuilder;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
*/
public class AddNewAccountActivity extends BaseActivity {
final Context ctx = this;
private Context appCtx;
private TinyDB tinyDB;
private View.OnClickListener onClickListener;
private ActivityAddNewAccountBinding viewBinding;
private enum Protocol {HTTPS, HTTP}
@Override
protected int getLayoutResourceId(){
return R.layout.activity_add_new_account;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
tinyDB = new TinyDB(appCtx);
viewBinding = ActivityAddNewAccountBinding.inflate(getLayoutInflater());
View view = viewBinding.getRoot();
setContentView(view);
getWindow().getDecorView().setBackground(new ColorDrawable(Color.TRANSPARENT));
initCloseListener();
viewBinding.close.setOnClickListener(onClickListener);
ArrayAdapter<AddNewAccountActivity.Protocol> adapterProtocols = new ArrayAdapter<>(AddNewAccountActivity.this, R.layout.spinner_item, AddNewAccountActivity.Protocol.values());
adapterProtocols.setDropDownViewResource(R.layout.spinner_dropdown_item);
viewBinding.protocolSpinner.setAdapter(adapterProtocols);
viewBinding.addNewAccount.setOnClickListener(login -> {
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
if(!connToInternet) {
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
}
else {
processLogin();
}
});
}
private void processLogin() {
try {
String instanceUrlET = viewBinding.instanceUrl.getText().toString();
String loginToken = viewBinding.loginToken.getText().toString();
Protocol protocol = (Protocol) viewBinding.protocolSpinner.getSelectedItem();
if(instanceUrlET.equals("")) {
Toasty.error(ctx, getResources().getString(R.string.emptyFieldURL));
return;
}
if(loginToken.equals("")) {
Toasty.error(ctx, getResources().getString(R.string.loginTokenError));
return;
}
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET, "http")).toUri();
URI instanceUrlWithProtocol = UrlBuilder.fromUri(rawInstanceUrl).withPath(PathsHelper.join(rawInstanceUrl.getPath()))
.withScheme(protocol.name().toLowerCase()).toUri();
URI instanceUrl = UrlBuilder.fromUri(instanceUrlWithProtocol).withPath(PathsHelper.join(instanceUrlWithProtocol.getPath(), "/api/v1/"))
.toUri();
versionCheck(instanceUrl.toString(), loginToken);
}
catch(Exception e) {
Log.e("onFailure-login", e.toString());
Toasty.error(ctx, getResources().getString(R.string.malformedUrl));
}
}
private void versionCheck(final String instanceUrl, final String loginToken) {
Call<GiteaVersion> callVersion;
callVersion = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithToken(loginToken);
callVersion.enqueue(new Callback<GiteaVersion>() {
@Override
public void onResponse(@NonNull final Call<GiteaVersion> callVersion, @NonNull retrofit2.Response<GiteaVersion> responseVersion) {
if(responseVersion.code() == 200) {
GiteaVersion version = responseVersion.body();
Version giteaVersion;
assert version != null;
try {
giteaVersion = new Version(version.getVersion());
}
catch(Exception e) {
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
return;
}
if(giteaVersion.less(getString(R.string.versionLow))) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx).setTitle(getString(R.string.versionAlertDialogHeader))
.setMessage(getResources().getString(R.string.versionUnsupportedOld, version.getVersion())).setIcon(R.drawable.ic_warning)
.setCancelable(true);
alertDialogBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> {
dialog.dismiss();
//enableProcessButton();
});
alertDialogBuilder.setPositiveButton(getString(R.string.textContinue), (dialog, which) -> {
dialog.dismiss();
login(instanceUrl, loginToken);
});
alertDialogBuilder.create().show();
}
else if(giteaVersion.lessOrEqual(getString(R.string.versionHigh))) {
login(instanceUrl, loginToken);
}
else {
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
login(instanceUrl, loginToken);
}
}
else if(responseVersion.code() == 403) {
login(instanceUrl, loginToken);
}
}
private void login(String instanceUrl, String loginToken) {
setupNewAccountWithToken(instanceUrl, loginToken);
}
@Override
public void onFailure(@NonNull Call<GiteaVersion> callVersion, @NonNull Throwable t) {
Log.e("onFailure-versionCheck", t.toString());
Toasty.error(ctx, getResources().getString(R.string.errorOnLogin));
}
});
}
private void setupNewAccountWithToken(String instanceUrl, final String loginToken) {
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserInfo("token " + loginToken);
call.enqueue(new Callback<UserInfo>() {
@Override
public void onResponse(@NonNull Call<UserInfo> call, @NonNull retrofit2.Response<UserInfo> response) {
UserInfo userDetails = response.body();
switch(response.code()) {
case 200:
assert userDetails != null;
// insert new account to db if does not exist
String accountName = userDetails.getUsername() + "@" + instanceUrl;
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
int checkAccount = userAccountsApi.getCount(accountName);
if(checkAccount == 0) {
userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
Toasty.success(ctx, getResources().getString(R.string.accountAddedMessage));
finish();
}
else {
Toasty.warning(ctx, getResources().getString(R.string.accountAlreadyExistsError));
}
break;
case 401:
Toasty.error(ctx,getResources().getString(R.string.unauthorizedApiError));
break;
default:
Toasty.error(ctx,getResources().getString(R.string.genericApiStatusError) + response.code());
}
}
@Override
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
Toasty.error(ctx,getResources().getString(R.string.genericError));
}
});
}
private void initCloseListener() {
onClickListener = view -> finish();
}
}

View File

@ -18,9 +18,9 @@ import org.mian.gitnex.R;
import org.mian.gitnex.adapters.UserSearchForTeamMemberAdapter;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.models.UserSearch;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -28,6 +28,10 @@ import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
*/
public class AddNewTeamMemberActivity extends BaseActivity {
private View.OnClickListener onClickListener;
@ -64,7 +68,7 @@ public class AddNewTeamMemberActivity extends BaseActivity {
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
ImageView closeActivity = findViewById(R.id.close);
addNewTeamMember = findViewById(R.id.addNewTeamMeber);
addNewTeamMember = findViewById(R.id.addNewTeamMember);
mRecyclerView = findViewById(R.id.recyclerViewUserSearch);
mProgressBar = findViewById(R.id.progress_bar);
noData = findViewById(R.id.noData);
@ -121,6 +125,8 @@ public class AddNewTeamMemberActivity extends BaseActivity {
Call<UserSearch> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserBySearch(Authorization.returnAuthentication(ctx, loginUid, token), searchKeyword, 10);
mProgressBar.setVisibility(View.VISIBLE);
call.enqueue(new Callback<UserSearch>() {
@Override

View File

@ -1,23 +1,23 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.gson.JsonElement;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.MultiSelectDialog;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Collaborators;
import org.mian.gitnex.models.Issues;
import org.mian.gitnex.models.MultiSelectModel;
import org.mian.gitnex.models.UpdateIssueAssignees;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
@ -139,7 +139,7 @@ public class AddRemoveAssigneesActivity extends BaseActivity {
.multiSelectList(listOfCollaborators)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
Log.i("selectedNames", String.valueOf(selectedNames));
@ -167,7 +167,7 @@ public class AddRemoveAssigneesActivity extends BaseActivity {
.multiSelectList(listOfCollaborators)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
updateIssueAssignees(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, loginUid, issueIndex, selectedNames);
tinyDb.putBoolean("singleIssueUpdate", true);
@ -207,17 +207,17 @@ public class AddRemoveAssigneesActivity extends BaseActivity {
}
else if(response.code() == 403) {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, getString(R.string.genericError));
Toasty.error(ctx, getString(R.string.genericError));
}
}
@ -254,7 +254,7 @@ public class AddRemoveAssigneesActivity extends BaseActivity {
if(response2.code() == 201) {
Toasty.info(ctx, ctx.getString(R.string.assigneesUpdated));
Toasty.success(ctx, ctx.getString(R.string.assigneesUpdated));
}
else if(response2.code() == 401) {
@ -267,17 +267,17 @@ public class AddRemoveAssigneesActivity extends BaseActivity {
}
else if(response2.code() == 403) {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response2.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, getString(R.string.genericError));
Toasty.error(ctx, getString(R.string.genericError));
}

View File

@ -1,25 +1,25 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.gson.JsonElement;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.MultiSelectDialog;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Labels;
import org.mian.gitnex.models.MultiSelectModel;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
@ -128,7 +128,7 @@ public class AddRemoveLabelsActivity extends BaseActivity {
.multiSelectList(listOfLabels)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
String labelIds = selectedIds.toString();
int[] integers;
@ -169,7 +169,7 @@ public class AddRemoveLabelsActivity extends BaseActivity {
.multiSelectList(listOfLabels)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
String labelIds = selectedIds.toString();
int[] integers;
@ -224,17 +224,17 @@ public class AddRemoveLabelsActivity extends BaseActivity {
}
else if(response.code() == 403) {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, getString(R.string.genericError));
Toasty.error(ctx, getString(R.string.genericError));
}
}
@ -265,7 +265,7 @@ public class AddRemoveLabelsActivity extends BaseActivity {
if(response.code() == 200) {
Toasty.info(ctx, ctx.getString(R.string.labelsUpdated));
Toasty.success(ctx, ctx.getString(R.string.labelsUpdated));
}
else if(response.code() == 401) {
@ -278,17 +278,17 @@ public class AddRemoveLabelsActivity extends BaseActivity {
}
else if(response.code() == 403) {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, getString(R.string.genericError));
Toasty.error(ctx, getString(R.string.genericError));
}

View File

@ -21,9 +21,9 @@ import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.AdminGetUsersAdapter;
import org.mian.gitnex.fragments.BottomSheetAdminUsersFragment;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.viewmodels.AdminGetUsersViewModel;
/**

View File

@ -1,5 +1,6 @@
package org.mian.gitnex.activities;
import android.content.Context;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import org.acra.ACRA;
@ -10,10 +11,11 @@ import org.acra.config.LimiterConfigurationBuilder;
import org.acra.config.MailSenderConfigurationBuilder;
import org.acra.data.StringFormat;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.FontsOverride;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.notifications.NotificationsMaster;
/**
* Author M M Arif
@ -26,10 +28,13 @@ import org.mian.gitnex.util.TinyDB;
public abstract class BaseActivity extends AppCompatActivity {
private Context appCtx;
@Override
public void onCreate(Bundle savedInstanceState) {
final TinyDB tinyDb = new TinyDB(getApplicationContext());
appCtx = getApplicationContext();
final TinyDB tinyDb = new TinyDB(appCtx);
switch(tinyDb.getInt("themeId")) {
@ -83,11 +88,17 @@ public abstract class BaseActivity extends AppCompatActivity {
}
// enabling counter badges by default
if(tinyDb.getString("enableCounterBadgesInit").isEmpty()) {
tinyDb.putBoolean("enableCounterBadges", true);
tinyDb.putString("enableCounterBadgesInit", "yes");
}
if(tinyDb.getInt("pollingDelayMinutes") == 0) {
tinyDb.putInt("pollingDelayMinutes", 15);
}
NotificationsMaster.hireWorker(appCtx);
// enabling counter badges by default
if(tinyDb.getString("enableCounterBadgesInit").isEmpty()) {
tinyDb.putBoolean("enableCounterBadges", true);
tinyDb.putString("enableCounterBadgesInit", "yes");
}
// enable crash reports by default
if(tinyDb.getString("crashReportingEnabledInit").isEmpty()) {
@ -103,6 +114,12 @@ public abstract class BaseActivity extends AppCompatActivity {
tinyDb.putString("cacheSizeImagesStr", getResources().getString(R.string.cacheSizeImagesSelectionSelectedText));
}
// enable comment drafts by default
if(tinyDb.getString("draftsCommentsDeletionEnabledInit").isEmpty()) {
tinyDb.putBoolean("draftsCommentsDeletionEnabled", true);
tinyDb.putString("draftsCommentsDeletionEnabledInit", "yes");
}
if(!tinyDb.getString("instanceUrlWithProtocol").endsWith("/")) {
tinyDb.putString("instanceUrlWithProtocol", tinyDb.getString("instanceUrlWithProtocol") + "/");

View File

@ -23,10 +23,10 @@ import org.mian.gitnex.adapters.CommitsAdapter;
import org.mian.gitnex.clients.AppApiService;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.interfaces.ApiInterface;
import org.mian.gitnex.models.Commits;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
@ -52,6 +52,7 @@ public class CommitsActivity extends BaseActivity {
private List<Commits> commitsList;
private CommitsAdapter adapter;
private ApiInterface api;
private ProgressBar progressLoadMore;
@Override
protected int getLayoutResourceId() {
@ -84,6 +85,7 @@ public class CommitsActivity extends BaseActivity {
ImageView closeActivity = findViewById(R.id.close);
noData = findViewById(R.id.noDataCommits);
progressLoadMore = findViewById(R.id.progressLoadMore);
progressBar = findViewById(R.id.progress_bar);
SwipeRefreshLayout swipeRefresh = findViewById(R.id.pullToRefresh);
@ -176,9 +178,7 @@ public class CommitsActivity extends BaseActivity {
private void loadMore(String token, String repoOwner, String repoName, final int page, String branchName, int resultLimit) {
//add loading progress view
commitsList.add(new Commits("load"));
adapter.notifyItemInserted((commitsList.size() - 1));
progressLoadMore.setVisibility(View.VISIBLE);
Call<List<Commits>> call = api.getRepositoryCommits(token, repoOwner, repoName, page, branchName, resultLimit);
@ -189,9 +189,6 @@ public class CommitsActivity extends BaseActivity {
if(response.isSuccessful()) {
//remove loading view
commitsList.remove(commitsList.size() - 1);
List<Commits> result = response.body();
assert result != null;
@ -208,6 +205,7 @@ public class CommitsActivity extends BaseActivity {
}
adapter.notifyDataChanged();
progressLoadMore.setVisibility(View.GONE);
}
else {

View File

@ -2,7 +2,6 @@ package org.mian.gitnex.activities;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -19,12 +18,14 @@ import com.google.gson.JsonElement;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Branches;
import org.mian.gitnex.models.DeleteFile;
import org.mian.gitnex.models.EditFile;
import org.mian.gitnex.models.NewFile;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
@ -45,8 +46,12 @@ public class CreateFileActivity extends BaseActivity {
private EditText newFileBranchName;
private EditText newFileCommitMessage;
private Spinner newFileBranchesSpinner;
private String filePath;
private String fileSha;
private int fileAction = 0; // 0 = create, 1 = delete, 2 = edit
final Context ctx = this;
private Context appCtx;
private TinyDB tinyDb;
List<Branches> branchesList = new ArrayList<>();
@ -60,12 +65,12 @@ public class CreateFileActivity extends BaseActivity {
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
tinyDb = new TinyDB(appCtx);
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
TinyDB tinyDb = new TinyDB(appCtx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
String repoFullName = tinyDb.getString("repoFullName");
@ -81,6 +86,8 @@ public class CreateFileActivity extends BaseActivity {
newFileCommitMessage = findViewById(R.id.newFileCommitMessage);
TextView branchNameId = findViewById(R.id.branchNameId);
TextView branchNameHintText = findViewById(R.id.branchNameHintText);
TextView toolbarTitle = findViewById(R.id.toolbarTitle);
TextView fileNameHint = findViewById(R.id.fileNameHint);
newFileName.requestFocus();
assert imm != null;
@ -91,11 +98,51 @@ public class CreateFileActivity extends BaseActivity {
newFileCreate = findViewById(R.id.newFileCreate);
if(getIntent().getStringExtra("filePath") != null && getIntent().getIntExtra("fileAction", 1) == 1) {
fileNameHint.setVisibility(View.GONE);
fileAction = getIntent().getIntExtra("fileAction", 1);
filePath = getIntent().getStringExtra("filePath");
String fileContents = getIntent().getStringExtra("fileContents");
fileSha = getIntent().getStringExtra("fileSha");
toolbarTitle.setText(getString(R.string.deleteFileText, filePath));
newFileCreate.setText(R.string.deleteFile);
newFileName.setText(filePath);
newFileName.setEnabled(false);
newFileName.setFocusable(false);
newFileContent.setText(fileContents);
newFileContent.setEnabled(false);
newFileContent.setFocusable(false);
}
if(getIntent().getStringExtra("filePath") != null && getIntent().getIntExtra("fileAction", 2) == 2) {
fileNameHint.setVisibility(View.GONE);
fileAction = getIntent().getIntExtra("fileAction", 2);
filePath = getIntent().getStringExtra("filePath");
String fileContents = getIntent().getStringExtra("fileContents");
fileSha = getIntent().getStringExtra("fileSha");
toolbarTitle.setText(getString(R.string.editFileText, filePath));
newFileCreate.setText(R.string.editFile);
newFileName.setText(filePath);
newFileName.setEnabled(false);
newFileName.setFocusable(false);
newFileContent.setText(fileContents);
}
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
newFileBranchesSpinner = findViewById(R.id.newFileBranchesSpinner);
newFileBranchesSpinner.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
newFileBranchesSpinner.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
getBranches(instanceUrl, instanceToken, repoOwner, repoName, loginUid);
newFileBranchesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
@ -129,15 +176,10 @@ public class CreateFileActivity extends BaseActivity {
if(!connToInternet) {
newFileCreate.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
newFileCreate.setBackground(shape);
} else {
}
else {
newFileCreate.setOnClickListener(createFileListener);
}
}
@ -166,14 +208,14 @@ public class CreateFileActivity extends BaseActivity {
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if(newFileName_.equals("") || newFileContent_.equals("") || newFileCommitMessage_.equals("")) {
Toasty.info(ctx, getString(R.string.newFileRequiredFields));
Toasty.error(ctx, getString(R.string.newFileRequiredFields));
return;
}
@ -181,13 +223,13 @@ public class CreateFileActivity extends BaseActivity {
if(currentBranch.toString().equals("No branch")) {
if(newFileBranchName_.equals("")) {
Toasty.info(ctx, getString(R.string.newFileRequiredFieldNewBranchName));
Toasty.error(ctx, getString(R.string.newFileRequiredFieldNewBranchName));
return;
}
else {
if(!appUtil.checkStringsWithDash(newFileBranchName_)) {
Toasty.info(ctx, getString(R.string.newFileInvalidBranchName));
Toasty.error(ctx, getString(R.string.newFileInvalidBranchName));
return;
}
@ -197,13 +239,28 @@ public class CreateFileActivity extends BaseActivity {
if(appUtil.charactersLength(newFileCommitMessage_) > 255) {
Toasty.info(ctx, getString(R.string.newFileCommitMessageError));
Toasty.warning(ctx, getString(R.string.newFileCommitMessageError));
}
else {
disableProcessButton();
createNewFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, newFileName_, appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, currentBranch.toString());
if(fileAction == 1) {
deleteFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, filePath,
newFileBranchName_, newFileCommitMessage_, currentBranch.toString(), fileSha);
}
else if(fileAction == 2) {
editFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, filePath,
appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, currentBranch.toString(), fileSha);
}
else {
createNewFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, newFileName_,
appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, currentBranch.toString());
}
}
@ -232,7 +289,7 @@ public class CreateFileActivity extends BaseActivity {
if(response.code() == 201) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.newFileSuccessMessage));
Toasty.success(ctx, getString(R.string.newFileSuccessMessage));
finish();
}
@ -249,11 +306,11 @@ public class CreateFileActivity extends BaseActivity {
if(response.code() == 404) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.apiNotFound));
Toasty.warning(ctx, getString(R.string.apiNotFound));
}
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.orgCreatedError));
Toasty.error(ctx, getString(R.string.orgCreatedError));
}
}
@ -262,6 +319,7 @@ public class CreateFileActivity extends BaseActivity {
@Override
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
enableProcessButton();
}
@ -269,6 +327,149 @@ public class CreateFileActivity extends BaseActivity {
}
private void deleteFile(final String instanceUrl, final String token, String repoOwner, String repoName, String fileName, String fileBranchName, String fileCommitMessage, String currentBranch, String fileSha) {
String branchName;
DeleteFile deleteFileJsonStr;
if(currentBranch.equals("No branch")) {
branchName = fileBranchName;
deleteFileJsonStr = new DeleteFile("", fileCommitMessage, fileBranchName, fileSha);
}
else {
branchName = currentBranch;
deleteFileJsonStr = new DeleteFile(currentBranch, fileCommitMessage, "", fileSha);
}
Call<JsonElement> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.deleteFile(token, repoOwner, repoName, fileName, deleteFileJsonStr);
call.enqueue(new Callback<JsonElement>() {
@Override
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
if(response.code() == 200) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.deleteFileMessage, branchName));
getIntent().removeExtra("filePath");
getIntent().removeExtra("fileSha");
getIntent().removeExtra("fileContents");
finish();
}
else if(response.code() == 401) {
enableProcessButton();
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
else {
if(response.code() == 404) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.apiNotFound));
}
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.genericError));
}
}
}
@Override
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
enableProcessButton();
}
});
}
private void editFile(final String instanceUrl, final String token, String repoOwner, String repoName, String fileName, String fileContent, String fileBranchName, String fileCommitMessage, String currentBranch, String fileSha) {
String branchName;
EditFile editFileJsonStr;
if(currentBranch.equals("No branch")) {
branchName = fileBranchName;
editFileJsonStr = new EditFile("", fileCommitMessage, fileBranchName, fileSha, fileContent);
}
else {
branchName = currentBranch;
editFileJsonStr = new EditFile(currentBranch, fileCommitMessage, "", fileSha, fileContent);
}
Call<JsonElement> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.editFile(token, repoOwner, repoName, fileName, editFileJsonStr);
call.enqueue(new Callback<JsonElement>() {
@Override
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
if(response.code() == 200) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.editFileMessage, branchName));
getIntent().removeExtra("filePath");
getIntent().removeExtra("fileSha");
getIntent().removeExtra("fileContents");
tinyDb.putBoolean("fileModified", true);
finish();
}
else if(response.code() == 401) {
enableProcessButton();
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
else {
if(response.code() == 404) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.apiNotFound));
}
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.genericError));
}
}
}
@Override
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
enableProcessButton();
}
});
}
private void getBranches(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid) {
Call<List<Branches>> call = RetrofitClient
@ -326,21 +527,11 @@ public class CreateFileActivity extends BaseActivity {
private void disableProcessButton() {
newFileCreate.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
newFileCreate.setBackground(shape);
}
private void enableProcessButton() {
newFileCreate.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
newFileCreate.setBackground(shape);
}
}

View File

@ -1,13 +1,8 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import android.app.DatePickerDialog;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -19,6 +14,7 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.google.gson.JsonElement;
import com.hendraanggrian.appcompat.socialview.Mention;
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
@ -26,22 +22,25 @@ import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.MultiSelectDialog;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.Collaborators;
import org.mian.gitnex.models.CreateIssue;
import org.mian.gitnex.models.Labels;
import org.mian.gitnex.models.Milestones;
import org.mian.gitnex.models.MultiSelectModel;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
@ -127,7 +126,7 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
newIssueDueDate.setOnClickListener(this);
newIssueMilestoneSpinner = findViewById(R.id.newIssueMilestoneSpinner);
newIssueMilestoneSpinner.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
newIssueMilestoneSpinner.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
getMilestones(instanceUrl, instanceToken, repoOwner, repoName, loginUid, resultLimit);
getLabels(instanceUrl, instanceToken, repoOwner, repoName, loginUid);
@ -138,15 +137,10 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
if(!connToInternet) {
createNewIssueButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createNewIssueButton.setBackground(shape);
} else {
}
else {
createNewIssueButton.setOnClickListener(this);
}
}
@ -175,21 +169,21 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if (newIssueTitleForm.equals("")) {
Toasty.info(ctx, getString(R.string.issueTitleEmpty));
Toasty.error(ctx, getString(R.string.issueTitleEmpty));
return;
}
/*if (newIssueDescriptionForm.equals("")) {
Toasty.info(ctx, getString(R.string.issueDescriptionEmpty));
Toasty.error(ctx, getString(R.string.issueDescriptionEmpty));
return;
}*/
@ -299,7 +293,7 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
TinyDB tinyDb = new TinyDB(appCtx);
tinyDb.putBoolean("resumeIssues", true);
Toasty.info(ctx, getString(R.string.issueCreated));
Toasty.success(ctx, getString(R.string.issueCreated));
enableProcessButton();
finish();
@ -317,7 +311,7 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
}
else {
Toasty.info(ctx, getString(R.string.issueCreatedError));
Toasty.error(ctx, getString(R.string.issueCreatedError));
enableProcessButton();
//Log.i("isSuccessful2", String.valueOf(response2.body()));
@ -335,12 +329,8 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
onClickListener = view -> finish();
}
private void getMilestones(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid, int resultLimit) {
@ -444,7 +434,7 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
.multiSelectList(listOfAssignees)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
assigneesList.setText(dataString);
@ -507,7 +497,7 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
.multiSelectList(listOfLabels)
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
public void onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
public void onSelected(List<Integer> selectedIds, List<String> selectedNames, String dataString) {
newIssueLabels.setText(dataString.trim());
labelsIdHolder.setText(selectedIds.toString());
@ -541,7 +531,7 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
multiSelectDialog.show(getSupportFragmentManager(), "multiSelectDialog");
}
else {
Toasty.info(ctx, getResources().getString(R.string.noAssigneesFound));
Toasty.warning(ctx, getResources().getString(R.string.noAssigneesFound));
}
}
else if (v == newIssueLabels) {
@ -549,7 +539,7 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
multiSelectDialogLabels.show(getSupportFragmentManager(), "multiSelectDialogLabels");
}
else {
Toasty.info(ctx, getResources().getString(R.string.noLabelsFound));
Toasty.warning(ctx, getResources().getString(R.string.noLabelsFound));
}
}
else if (v == newIssueDueDate) {
@ -581,20 +571,10 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
private void disableProcessButton() {
createNewIssueButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createNewIssueButton.setBackground(shape);
}
private void enableProcessButton() {
createNewIssueButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
createNewIssueButton.setBackground(shape);
}
}

View File

@ -1,13 +1,7 @@
package org.mian.gitnex.activities;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import retrofit2.Call;
import retrofit2.Callback;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -16,19 +10,24 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import com.pes.androidmaterialcolorpickerdialog.ColorPicker;
import com.pes.androidmaterialcolorpickerdialog.ColorPickerCallback;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.CreateLabel;
import org.mian.gitnex.models.Labels;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.viewmodels.LabelsViewModel;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
@ -118,38 +117,23 @@ public class CreateLabelActivity extends BaseActivity {
createLabelButton.setText(getResources().getString(R.string.newUpdateButtonCopy));
createLabelButton.setOnClickListener(updateLabelListener);
return;
}
if(!connToInternet) {
createLabelButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createLabelButton.setBackground(shape);
} else {
}
else {
createLabelButton.setOnClickListener(createLabelListener);
}
}
private View.OnClickListener createLabelListener = new View.OnClickListener() {
public void onClick(View v) {
processCreateLabel();
}
};
private View.OnClickListener createLabelListener = v -> processCreateLabel();
private View.OnClickListener updateLabelListener = new View.OnClickListener() {
public void onClick(View v) {
processUpdateLabel();
}
};
private View.OnClickListener updateLabelListener = v -> processUpdateLabel();
private void processUpdateLabel() {
@ -176,27 +160,28 @@ public class CreateLabelActivity extends BaseActivity {
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if(updateLabelName.equals("")) {
Toasty.info(ctx, getString(R.string.labelEmptyError));
Toasty.error(ctx, getString(R.string.labelEmptyError));
return;
}
if(!appUtil.checkStrings(updateLabelName)) {
Toasty.info(ctx, getString(R.string.labelNameError));
Toasty.error(ctx, getString(R.string.labelNameError));
return;
}
disableProcessButton();
patchLabel(instanceUrl, instanceToken, repoOwner, repoName, updateLabelName, updateLabelColor, Integer.valueOf(getIntent().getStringExtra("labelId")), loginUid);
patchLabel(instanceUrl, instanceToken, repoOwner, repoName, updateLabelName, updateLabelColor, Integer.parseInt(
Objects.requireNonNull(getIntent().getStringExtra("labelId"))), loginUid);
}
@ -224,21 +209,21 @@ public class CreateLabelActivity extends BaseActivity {
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if(newLabelName.equals("")) {
Toasty.info(ctx, getString(R.string.labelEmptyError));
Toasty.error(ctx, getString(R.string.labelEmptyError));
return;
}
if(!appUtil.checkStrings(newLabelName)) {
Toasty.info(ctx, getString(R.string.labelNameError));
Toasty.error(ctx, getString(R.string.labelNameError));
return;
}
@ -267,7 +252,7 @@ public class CreateLabelActivity extends BaseActivity {
if(response.code() == 201) {
Toasty.info(ctx, getString(R.string.labelCreated));
Toasty.success(ctx, getString(R.string.labelCreated));
tinyDb.putString("labelColor", "");
tinyDb.putBoolean("labelsRefresh", true);
finish();
@ -286,7 +271,7 @@ public class CreateLabelActivity extends BaseActivity {
enableProcessButton();
tinyDb.putString("labelColor", "");
Toasty.info(ctx, getString(R.string.labelGeneralError));
Toasty.error(ctx, getString(R.string.labelGeneralError));
}
@ -294,6 +279,7 @@ public class CreateLabelActivity extends BaseActivity {
@Override
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
tinyDb.putString("labelColor", "");
Log.e("onFailure", t.toString());
enableProcessButton();
@ -322,7 +308,7 @@ public class CreateLabelActivity extends BaseActivity {
if(response.isSuccessful()) {
if(response.code() == 200) {
Toasty.info(ctx, getString(R.string.labelUpdated));
Toasty.success(ctx, getString(R.string.labelUpdated));
tinyDb.putString("labelColor", "");
tinyDb.putBoolean("labelsRefresh", true);
tinyDb.putString("labelColorDefault", "");
@ -348,7 +334,7 @@ public class CreateLabelActivity extends BaseActivity {
enableProcessButton();
tinyDb.putString("labelColor", "");
tinyDb.putString("labelColorDefault", "");
Toasty.info(ctx, getString(R.string.labelGeneralError));
Toasty.error(ctx, getString(R.string.labelGeneralError));
}
@ -356,6 +342,7 @@ public class CreateLabelActivity extends BaseActivity {
@Override
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
tinyDb.putString("labelColor", "");
tinyDb.putString("labelColorDefault", "");
Log.e("onFailure", t.toString());
@ -395,7 +382,7 @@ public class CreateLabelActivity extends BaseActivity {
if(response.isSuccessful()) {
if(response.code() == 204) {
Toasty.info(ctx, getString(R.string.labelDeleteText));
Toasty.success(ctx, getString(R.string.labelDeleteText));
LabelsViewModel.loadLabelsList(instanceUrl, instanceToken, repoOwner, repoName, ctx);
getIntent().removeExtra("labelAction");
getIntent().removeExtra("labelId");
@ -412,7 +399,7 @@ public class CreateLabelActivity extends BaseActivity {
}
else {
Toasty.info(ctx, getString(R.string.labelDeleteErrorText));
Toasty.error(ctx, getString(R.string.labelDeleteErrorText));
}
@ -429,21 +416,11 @@ public class CreateLabelActivity extends BaseActivity {
private void disableProcessButton() {
createLabelButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createLabelButton.setBackground(shape);
}
private void enableProcessButton() {
createLabelButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
createLabelButton.setBackground(shape);
}
}

View File

@ -1,11 +1,7 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import android.app.DatePickerDialog;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -14,16 +10,19 @@ import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.Milestones;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.Calendar;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
@ -71,24 +70,15 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
if(!connToInternet) {
createNewMilestoneButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createNewMilestoneButton.setBackground(shape);
} else {
}
else {
createNewMilestoneButton.setOnClickListener(createMilestoneListener);
}
}
private View.OnClickListener createMilestoneListener = new View.OnClickListener() {
public void onClick(View v) {
processNewMilestone();
}
};
private View.OnClickListener createMilestoneListener = v -> processNewMilestone();
private void processNewMilestone() {
@ -110,14 +100,14 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if(newMilestoneTitle.equals("")) {
Toasty.info(ctx, getString(R.string.milestoneNameErrorEmpty));
Toasty.error(ctx, getString(R.string.milestoneNameErrorEmpty));
return;
}
@ -125,7 +115,7 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
if(!newMilestoneDescription.equals("")) {
if (appUtil.charactersLength(newMilestoneDescription) > 255) {
Toasty.info(ctx, getString(R.string.milestoneDescError));
Toasty.warning(ctx, getString(R.string.milestoneDescError));
return;
}
@ -133,10 +123,13 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
String finalMilestoneDueDate = null;
if(!newMilestoneDueDate.isEmpty()) {
finalMilestoneDueDate = (AppUtil.customDateCombine(AppUtil.customDateFormat(newMilestoneDueDate)));
} else if (new Version(tinyDb.getString("giteaVersion")).less("1.10.0")) {
}
else if (new Version(tinyDb.getString("giteaVersion")).less("1.10.0")) {
// if Gitea version is less than 1.10.0 DueDate is required
Toasty.info(ctx, getString(R.string.milestoneDateEmpty));
Toasty.warning(ctx, getString(R.string.milestoneDateEmpty));
return;
}
@ -166,7 +159,7 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
TinyDB tinyDb = new TinyDB(appCtx);
tinyDb.putBoolean("milestoneCreated", true);
Toasty.info(ctx, getString(R.string.milestoneCreated));
Toasty.success(ctx, getString(R.string.milestoneCreated));
enableProcessButton();
finish();
@ -184,7 +177,7 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.milestoneCreatedError));
Toasty.error(ctx, getString(R.string.milestoneCreatedError));
}
@ -226,32 +219,18 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
onClickListener = view -> finish();
}
private void disableProcessButton() {
createNewMilestoneButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createNewMilestoneButton.setBackground(shape);
}
private void enableProcessButton() {
createNewMilestoneButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
createNewMilestoneButton.setBackground(shape);
}
}

View File

@ -1,10 +1,6 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.util.Patterns;
@ -13,14 +9,17 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
@ -69,11 +68,10 @@ public class CreateNewUserActivity extends BaseActivity {
if(!connToInternet) {
disableProcessButton();
} else {
}
else {
createUserButton.setOnClickListener(createNewUserListener);
}
}
@ -94,35 +92,35 @@ public class CreateNewUserActivity extends BaseActivity {
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if(newFullName.equals("") || newUserName.equals("") | newUserEmail.equals("") || newUserPassword.equals("")) {
Toasty.info(ctx, getString(R.string.emptyFields));
Toasty.error(ctx, getString(R.string.emptyFields));
return;
}
if(!appUtil.checkStrings(newFullName)) {
Toasty.info(ctx, getString(R.string.userInvalidFullName));
Toasty.error(ctx, getString(R.string.userInvalidFullName));
return;
}
if(!appUtil.checkStringsWithAlphaNumeric(newUserName)) {
Toasty.info(ctx, getString(R.string.userInvalidUserName));
Toasty.error(ctx, getString(R.string.userInvalidUserName));
return;
}
if(!Patterns.EMAIL_ADDRESS.matcher(newUserEmail).matches()) {
Toasty.info(ctx, getString(R.string.userInvalidEmail));
Toasty.error(ctx, getString(R.string.userInvalidEmail));
return;
}
@ -150,7 +148,7 @@ public class CreateNewUserActivity extends BaseActivity {
if(response.code() == 201) {
Toasty.info(ctx, getString(R.string.userCreatedText));
Toasty.success(ctx, getString(R.string.userCreatedText));
enableProcessButton();
finish();
@ -167,25 +165,25 @@ public class CreateNewUserActivity extends BaseActivity {
else if(response.code() == 403) {
enableProcessButton();
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
enableProcessButton();
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else if(response.code() == 422) {
enableProcessButton();
Toasty.info(ctx, ctx.getString(R.string.userExistsError));
Toasty.warning(ctx, ctx.getString(R.string.userExistsError));
}
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.genericError));
Toasty.error(ctx, getString(R.string.genericError));
}
@ -193,6 +191,7 @@ public class CreateNewUserActivity extends BaseActivity {
@Override
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
enableProcessButton();
}
@ -200,39 +199,21 @@ public class CreateNewUserActivity extends BaseActivity {
}
private View.OnClickListener createNewUserListener = new View.OnClickListener() {
public void onClick(View v) {
processCreateNewUser();
}
};
private View.OnClickListener createNewUserListener = v -> processCreateNewUser();
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
onClickListener = view -> finish();
}
private void disableProcessButton() {
createUserButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createUserButton.setBackground(shape);
}
private void enableProcessButton() {
createUserButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
createUserButton.setBackground(shape);
}
}

View File

@ -1,23 +1,22 @@
package org.mian.gitnex.activities;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import androidx.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.UserOrganizations;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import retrofit2.Call;
import retrofit2.Callback;
@ -67,15 +66,10 @@ public class CreateOrganizationActivity extends BaseActivity {
if(!connToInternet) {
createOrganizationButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createOrganizationButton.setBackground(shape);
} else {
}
else {
createOrganizationButton.setOnClickListener(createOrgListener);
}
}
@ -109,7 +103,7 @@ public class CreateOrganizationActivity extends BaseActivity {
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
@ -117,7 +111,7 @@ public class CreateOrganizationActivity extends BaseActivity {
if(!newOrgDesc.equals("")) {
if (appUtil.charactersLength(newOrgDesc) > 255) {
Toasty.info(ctx, getString(R.string.orgDescError));
Toasty.warning(ctx, getString(R.string.orgDescError));
return;
}
@ -125,12 +119,12 @@ public class CreateOrganizationActivity extends BaseActivity {
if(newOrgName.equals("")) {
Toasty.info(ctx, getString(R.string.orgNameErrorEmpty));
Toasty.error(ctx, getString(R.string.orgNameErrorEmpty));
}
else if(!appUtil.checkStrings(newOrgName)) {
Toasty.info(ctx, getString(R.string.orgNameErrorInvalid));
Toasty.warning(ctx, getString(R.string.orgNameErrorInvalid));
}
else {
@ -161,7 +155,7 @@ public class CreateOrganizationActivity extends BaseActivity {
TinyDB tinyDb = new TinyDB(appCtx);
tinyDb.putBoolean("orgCreated", true);
enableProcessButton();
Toasty.info(ctx, getString(R.string.orgCreated));
Toasty.success(ctx, getString(R.string.orgCreated));
finish();
}
@ -177,24 +171,24 @@ public class CreateOrganizationActivity extends BaseActivity {
else if(response.code() == 409) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.orgExistsError));
Toasty.warning(ctx, getString(R.string.orgExistsError));
}
else if(response.code() == 422) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.orgExistsError));
Toasty.warning(ctx, getString(R.string.orgExistsError));
}
else {
if(response.code() == 404) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.apiNotFound));
Toasty.warning(ctx, getString(R.string.apiNotFound));
}
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.orgCreatedError));
Toasty.error(ctx, getString(R.string.orgCreatedError));
}
}
@ -213,21 +207,11 @@ public class CreateOrganizationActivity extends BaseActivity {
private void disableProcessButton() {
createOrganizationButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createOrganizationButton.setBackground(shape);
}
private void enableProcessButton() {
createOrganizationButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
createOrganizationButton.setBackground(shape);
}
}

View File

@ -1,11 +1,7 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -17,17 +13,20 @@ import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import androidx.annotation.NonNull;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Branches;
import org.mian.gitnex.models.Releases;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
@ -88,7 +87,7 @@ public class CreateReleaseActivity extends BaseActivity {
closeActivity.setOnClickListener(onClickListener);
releaseBranch = findViewById(R.id.releaseBranch);
releaseBranch.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
releaseBranch.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
getBranches(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
releaseBranch.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
@ -108,20 +107,15 @@ public class CreateReleaseActivity extends BaseActivity {
if(!connToInternet) {
disableProcessButton();
} else {
}
else {
createNewRelease.setOnClickListener(createReleaseListener);
}
}
private View.OnClickListener createReleaseListener = new View.OnClickListener() {
public void onClick(View v) {
processNewRelease();
}
};
private View.OnClickListener createReleaseListener = v -> processNewRelease();
private void processNewRelease() {
@ -145,21 +139,21 @@ public class CreateReleaseActivity extends BaseActivity {
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if(newReleaseTagName.equals("")) {
Toasty.info(ctx, getString(R.string.tagNameErrorEmpty));
Toasty.error(ctx, getString(R.string.tagNameErrorEmpty));
return;
}
if(newReleaseTitle.equals("")) {
Toasty.info(ctx, getString(R.string.titleErrorEmpty));
Toasty.error(ctx, getString(R.string.titleErrorEmpty));
return;
}
@ -189,7 +183,7 @@ public class CreateReleaseActivity extends BaseActivity {
TinyDB tinyDb = new TinyDB(appCtx);
tinyDb.putBoolean("updateReleases", true);
Toasty.info(ctx, getString(R.string.releaseCreatedText));
Toasty.success(ctx, getString(R.string.releaseCreatedText));
enableProcessButton();
finish();
@ -206,19 +200,19 @@ public class CreateReleaseActivity extends BaseActivity {
else if(response.code() == 403) {
enableProcessButton();
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
enableProcessButton();
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
enableProcessButton();
Toasty.info(ctx, ctx.getString(R.string.genericError));
Toasty.error(ctx, ctx.getString(R.string.genericError));
}
@ -302,21 +296,11 @@ public class CreateReleaseActivity extends BaseActivity {
private void disableProcessButton() {
createNewRelease.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createNewRelease.setBackground(shape);
}
private void enableProcessButton() {
createNewRelease.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
createNewRelease.setBackground(shape);
}
}

View File

@ -2,9 +2,7 @@ package org.mian.gitnex.activities;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import androidx.annotation.NonNull;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@ -15,15 +13,16 @@ import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import androidx.annotation.NonNull;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.OrgOwner;
import org.mian.gitnex.models.OrganizationRepository;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@ -87,8 +86,9 @@ public class CreateRepoActivity extends BaseActivity {
closeActivity.setOnClickListener(onClickListener);
spinner = findViewById(R.id.ownerSpinner);
spinner.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
spinner.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
getOrganizations(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), userLogin);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
@ -107,12 +107,10 @@ public class CreateRepoActivity extends BaseActivity {
if(!connToInternet) {
disableProcessButton();
}
else {
createRepo.setOnClickListener(createRepoListener);
}
}
@ -138,45 +136,38 @@ public class CreateRepoActivity extends BaseActivity {
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if(!newRepoDesc.equals("")) {
if (appUtil.charactersLength(newRepoDesc) > 255) {
Toasty.info(ctx, getString(R.string.repoDescError));
Toasty.warning(ctx, getString(R.string.repoDescError));
return;
}
}
if(newRepoName.equals("")) {
Toasty.info(ctx, getString(R.string.repoNameErrorEmpty));
Toasty.error(ctx, getString(R.string.repoNameErrorEmpty));
}
else if(!appUtil.checkStrings(newRepoName)) {
Toasty.info(ctx, getString(R.string.repoNameErrorInvalid));
Toasty.warning(ctx, getString(R.string.repoNameErrorInvalid));
}
else if (reservedRepoNames.contains(newRepoName)) {
Toasty.info(ctx, getString(R.string.repoNameErrorReservedName));
Toasty.warning(ctx, getString(R.string.repoNameErrorReservedName));
}
else if (reservedRepoPatterns.matcher(newRepoName).find()) {
Toasty.info(ctx, getString(R.string.repoNameErrorReservedPatterns));
Toasty.warning(ctx, getString(R.string.repoNameErrorReservedPatterns));
}
else {
disableProcessButton();
createNewRepository(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), loginUid, newRepoName, newRepoDesc, repoOwner, newRepoAccess);
}
}
@ -191,7 +182,6 @@ public class CreateRepoActivity extends BaseActivity {
.getInstance(instanceUrl, ctx)
.getApiInterface()
.createNewUserRepository(token, createRepository);
}
else {
@ -199,7 +189,6 @@ public class CreateRepoActivity extends BaseActivity {
.getInstance(instanceUrl, ctx)
.getApiInterface()
.createNewUserOrgRepository(token, repoOwner, createRepository);
}
call.enqueue(new Callback<OrganizationRepository>() {
@ -211,7 +200,7 @@ public class CreateRepoActivity extends BaseActivity {
TinyDB tinyDb = new TinyDB(appCtx);
tinyDb.putBoolean("repoCreated", true);
Toasty.info(ctx, getString(R.string.repoCreated));
Toasty.success(ctx, getString(R.string.repoCreated));
enableProcessButton();
finish();
}
@ -222,25 +211,23 @@ public class CreateRepoActivity extends BaseActivity {
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
else if(response.code() == 409) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.repoExistsError));
Toasty.warning(ctx, getString(R.string.repoExistsError));
}
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.repoCreatedError));
Toasty.error(ctx, getString(R.string.repoCreatedError));
}
}
@Override
public void onFailure(@NonNull Call<OrganizationRepository> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
enableProcessButton();
}
@ -271,13 +258,16 @@ public class CreateRepoActivity extends BaseActivity {
organizationsList.add(new OrgOwner(userLogin));
assert organizationsList_ != null;
if(organizationsList_.size() > 0) {
for (int i = 0; i < organizationsList_.size(); i++) {
if(!tinyDb.getString("organizationId").isEmpty()) {
if (Integer.parseInt(tinyDb.getString("organizationId")) == organizationsList_.get(i).getId()) {
organizationId = i + 1;
}
}
OrgOwner data = new OrgOwner(
organizationsList_.get(i).getUsername()
);
@ -293,6 +283,7 @@ public class CreateRepoActivity extends BaseActivity {
spinner.setAdapter(adapter);
if (tinyDb.getBoolean("organizationAction") & organizationId != 0) {
spinner.setSelection(organizationId);
tinyDb.putBoolean("organizationAction", false);
}
@ -308,13 +299,13 @@ public class CreateRepoActivity extends BaseActivity {
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
}
@Override
public void onFailure(@NonNull Call<List<OrgOwner>> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
enableProcessButton();
}
@ -322,32 +313,18 @@ public class CreateRepoActivity extends BaseActivity {
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
onClickListener = view -> finish();
}
private void disableProcessButton() {
createRepo.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
createRepo.setBackground(shape);
}
private void enableProcessButton() {
createRepo.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
createRepo.setBackground(shape);
}
}

View File

@ -1,30 +1,29 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import retrofit2.Call;
import retrofit2.Callback;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Teams;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import android.util.Log;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
@ -98,134 +97,120 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
teamPermission.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
teamPermission.setOnClickListener(view -> {
AlertDialog.Builder pBuilder = new AlertDialog.Builder(ctx);
pBuilder.setTitle(R.string.newTeamPermission);
if(permissionSelectedChoice != -1) {
pBuilder.setCancelable(true);
}
else {
pBuilder.setCancelable(false);
}
pBuilder.setSingleChoiceItems(permissionList, permissionSelectedChoice, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
permissionSelectedChoice = i;
teamPermission.setText(permissionList[i]);
if(permissionList[i].equals("Read")) {
teamPermissionDetail.setVisibility(View.VISIBLE);
teamPermissionDetail.setText(R.string.newTeamPermissionRead);
}
else if(permissionList[i].equals("Write")) {
teamPermissionDetail.setVisibility(View.VISIBLE);
teamPermissionDetail.setText(R.string.newTeamPermissionWrite);
}
else if(permissionList[i].equals("Admin")) {
teamPermissionDetail.setVisibility(View.VISIBLE);
teamPermissionDetail.setText(R.string.newTeamPermissionAdmin);
}
else {
teamPermissionDetail.setVisibility(View.GONE);
}
dialogInterface.dismiss();
}
});
AlertDialog pDialog = pBuilder.create();
pDialog.show();
AlertDialog.Builder pBuilder = new AlertDialog.Builder(ctx);
pBuilder.setTitle(R.string.newTeamPermission);
if(permissionSelectedChoice != -1) {
pBuilder.setCancelable(true);
}
else {
pBuilder.setCancelable(false);
}
pBuilder.setSingleChoiceItems(permissionList, permissionSelectedChoice, (dialogInterface, i) -> {
permissionSelectedChoice = i;
teamPermission.setText(permissionList[i]);
switch(permissionList[i]) {
case "Read":
teamPermissionDetail.setVisibility(View.VISIBLE);
teamPermissionDetail.setText(R.string.newTeamPermissionRead);
break;
case "Write":
teamPermissionDetail.setVisibility(View.VISIBLE);
teamPermissionDetail.setText(R.string.newTeamPermissionWrite);
break;
case "Admin":
teamPermissionDetail.setVisibility(View.VISIBLE);
teamPermissionDetail.setText(R.string.newTeamPermissionAdmin);
break;
default:
teamPermissionDetail.setVisibility(View.GONE);
break;
}
dialogInterface.dismiss();
});
AlertDialog pDialog = pBuilder.create();
pDialog.show();
});
teamAccessControls.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
teamAccessControls.setOnClickListener(v -> {
teamAccessControls.setText("");
teamAccessControlsArray.setText("");
pushAccessList = Arrays.asList(accessControlsList);
teamAccessControls.setText("");
teamAccessControlsArray.setText("");
pushAccessList = Arrays.asList(accessControlsList);
AlertDialog.Builder aDialogBuilder = new AlertDialog.Builder(ctx);
AlertDialog.Builder aDialogBuilder = new AlertDialog.Builder(ctx);
aDialogBuilder.setMultiChoiceItems(accessControlsList, selectedAccessControlsTrueFalse, new DialogInterface.OnMultiChoiceClickListener() {
aDialogBuilder.setMultiChoiceItems(accessControlsList, selectedAccessControlsTrueFalse, (dialog, which, isChecked) -> {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
})
.setCancelable(false)
.setTitle(R.string.newTeamAccessControls)
.setPositiveButton(R.string.okButton, (dialog, which) -> {
int selectedVal = 0;
while(selectedVal < selectedAccessControlsTrueFalse.length)
{
boolean value = selectedAccessControlsTrueFalse[selectedVal];
String repoCode = "";
if(selectedVal == 0) {
repoCode = "repo.code";
}
if(selectedVal == 1) {
repoCode = "repo.issues";
}
if(selectedVal == 2) {
repoCode = "repo.pulls";
}
if(selectedVal == 3) {
repoCode = "repo.releases";
}
if(selectedVal == 4) {
repoCode = "repo.wiki";
}
if(selectedVal == 5) {
repoCode = "repo.ext_wiki";
}
if(selectedVal == 6) {
repoCode = "repo.ext_issues";
}
})
.setCancelable(false)
.setTitle(R.string.newTeamAccessControls)
.setPositiveButton(R.string.okButton, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int selectedVal = 0;
while(selectedVal < selectedAccessControlsTrueFalse.length)
{
boolean value = selectedAccessControlsTrueFalse[selectedVal];
String repoCode = "";
if(selectedVal == 0) {
repoCode = "repo.code";
}
if(selectedVal == 1) {
repoCode = "repo.issues";
}
if(selectedVal == 2) {
repoCode = "repo.pulls";
}
if(selectedVal == 3) {
repoCode = "repo.releases";
}
if(selectedVal == 4) {
repoCode = "repo.wiki";
}
if(selectedVal == 5) {
repoCode = "repo.ext_wiki";
}
if(selectedVal == 6) {
repoCode = "repo.ext_issues";
}
if(value){
teamAccessControls.setText(getString(R.string.newTeamPermissionValues, teamAccessControls.getText(), pushAccessList.get(selectedVal)));
teamAccessControlsArray.setText(getString(R.string.newTeamPermissionValuesFinal, teamAccessControlsArray.getText(), repoCode));
}
selectedVal++;
}
String data = String.valueOf(teamAccessControls.getText());
if(!data.equals("")) {
teamAccessControls.setText(data.substring(0, data.length() - 2));
}
String dataArray = String.valueOf(teamAccessControlsArray.getText());
if(!dataArray.equals("")) {
teamAccessControlsArray.setText(dataArray.substring(0, dataArray.length() - 2));
}
//Log.i("orgName", String.valueOf(teamAccessControlsArray.getText()));
if(value){
teamAccessControls.setText(getString(R.string.newTeamPermissionValues, teamAccessControls.getText(), pushAccessList.get(selectedVal)));
teamAccessControlsArray.setText(getString(R.string.newTeamPermissionValuesFinal, teamAccessControlsArray.getText(), repoCode));
}
selectedVal++;
}
});
String data = String.valueOf(teamAccessControls.getText());
if(!data.equals("")) {
teamAccessControls.setText(data.substring(0, data.length() - 2));
}
AlertDialog aDialog = aDialogBuilder.create();
aDialog.show();
}
String dataArray = String.valueOf(teamAccessControlsArray.getText());
if(!dataArray.equals("")) {
teamAccessControlsArray.setText(dataArray.substring(0, dataArray.length() - 2));
}
//Log.i("orgName", String.valueOf(teamAccessControlsArray.getText()));
});
AlertDialog aDialog = aDialogBuilder.create();
aDialog.show();
});
createTeamButton.setEnabled(false);
@ -264,21 +249,21 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if (newTeamName.equals("")) {
Toasty.info(ctx, getString(R.string.teamNameEmpty));
Toasty.error(ctx, getString(R.string.teamNameEmpty));
return;
}
if(!appUtil.checkStringsWithAlphaNumericDashDotUnderscore(newTeamName)) {
Toasty.info(ctx, getString(R.string.teamNameError));
Toasty.warning(ctx, getString(R.string.teamNameError));
return;
}
@ -286,12 +271,12 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
if(!newTeamDesc.equals("")) {
if(!appUtil.checkStrings(newTeamDesc)) {
Toasty.info(ctx, getString(R.string.teamDescError));
Toasty.warning(ctx, getString(R.string.teamDescError));
return;
}
if(newTeamDesc.length() > 100) {
Toasty.info(ctx, getString(R.string.teamDescLimit));
Toasty.warning(ctx, getString(R.string.teamDescLimit));
return;
}
@ -299,7 +284,7 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
if (newTeamPermission.equals("")) {
Toasty.info(ctx, getString(R.string.teamPermissionEmpty));
Toasty.error(ctx, getString(R.string.teamPermissionEmpty));
return;
}
@ -336,16 +321,14 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
TinyDB tinyDb = new TinyDB(appCtx);
tinyDb.putBoolean("resumeTeams", true);
Toasty.info(ctx, getString(R.string.teamCreated));
Toasty.success(ctx, getString(R.string.teamCreated));
finish();
}
}
else if(response2.code() == 404) {
Toasty.info(ctx, getString(R.string.apiNotFound));
Toasty.warning(ctx, getString(R.string.apiNotFound));
}
else if(response2.code() == 401) {
@ -353,12 +336,10 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
else {
Toasty.info(ctx, getString(R.string.teamCreatedError));
Toasty.error(ctx, getString(R.string.teamCreatedError));
}
}
@ -373,19 +354,15 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
@Override
public void onClick(View v) {
if(v == createTeamButton) {
processCreateTeam();
}
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
onClickListener = view -> finish();
}
}

View File

@ -1,68 +0,0 @@
package org.mian.gitnex.activities;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.CreditsAdapter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Author M M Arif
*/
public class CreditsActivity extends BaseActivity {
private View.OnClickListener onClickListener;
final Context ctx = this;
@Override
protected int getLayoutResourceId(){
return R.layout.activity_credits;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ImageView closeActivity = findViewById(R.id.close);
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
Resources res = getResources();
CharSequence[] creditsInfo = res.getTextArray(R.array.creditsInfo);
List<CharSequence> creditsList = new ArrayList<>(Arrays.asList(creditsInfo));
RecyclerView mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
DividerItemDecoration.VERTICAL);
mRecyclerView.addItemDecoration(dividerItemDecoration);
CreditsAdapter adapter = new CreditsAdapter(creditsList);
mRecyclerView.setAdapter(adapter);
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
}
}

View File

@ -1,14 +1,9 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -20,6 +15,7 @@ import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.google.gson.JsonElement;
import com.hendraanggrian.appcompat.socialview.Mention;
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
@ -27,21 +23,24 @@ import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.Collaborators;
import org.mian.gitnex.models.CreateIssue;
import org.mian.gitnex.models.Issues;
import org.mian.gitnex.models.Milestones;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
@ -109,7 +108,7 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
loadCollaboratorsList();
editIssueMilestoneSpinner = findViewById(R.id.editIssueMilestoneSpinner);
editIssueMilestoneSpinner.getBackground().setColorFilter(getResources().getColor(R.color.white), PorterDuff.Mode.SRC_ATOP);
editIssueMilestoneSpinner.getBackground().setColorFilter(getResources().getColor(R.color.colorWhite), PorterDuff.Mode.SRC_ATOP);
editIssueDescription.setMentionAdapter(defaultMentionAdapter);
@ -121,7 +120,7 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
if(!tinyDb.getString("issueNumber").isEmpty()) {
if(tinyDb.getString("issueType").equals("pr")) {
if(tinyDb.getString("issueType").equalsIgnoreCase("Pull")) {
toolbar_title.setText(getString(R.string.editPrNavHeader, String.valueOf(issueIndex)));
}
else {
@ -217,14 +216,14 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if (editIssueTitleForm.equals("")) {
Toasty.info(ctx, getString(R.string.issueTitleEmpty));
Toasty.error(ctx, getString(R.string.issueTitleEmpty));
return;
}
@ -266,11 +265,11 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
if(response.code() == 201) {
if(tinyDb.getString("issueType").equals("pr")) {
Toasty.info(ctx, getString(R.string.editPrSuccessMessage));
if(tinyDb.getString("issueType").equalsIgnoreCase("Pull")) {
Toasty.success(ctx, getString(R.string.editPrSuccessMessage));
}
else {
Toasty.info(ctx, getString(R.string.editIssueSuccessMessage));
Toasty.success(ctx, getString(R.string.editIssueSuccessMessage));
}
tinyDb.putBoolean("issueEdited", true);
@ -290,7 +289,7 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.genericError));
Toasty.error(ctx, getString(R.string.genericError));
}
@ -427,7 +426,6 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
@SuppressLint("SimpleDateFormat") DateFormat formatter = new SimpleDateFormat("yyyy-M-dd");
String dueDate = formatter.format(response.body().getDue_date());
editIssueDueDate.setText(dueDate);
}
//enableProcessButton();
@ -438,12 +436,10 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
else {
Toasty.info(ctx, getString(R.string.genericError));
Toasty.error(ctx, getString(R.string.genericError));
}
}
@ -459,21 +455,11 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
private void disableProcessButton() {
editIssueButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
editIssueButton.setBackground(shape);
}
private void enableProcessButton() {
editIssueButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
editIssueButton.setBackground(shape);
}
}

View File

@ -14,12 +14,12 @@ import org.mian.gitnex.R;
import org.mian.gitnex.adapters.FilesDiffAdapter;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.ParseDiff;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.FileDiffView;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.io.IOException;
import java.util.List;
import okhttp3.ResponseBody;
@ -82,8 +82,9 @@ public class FileDiffActivity extends BaseActivity {
// fallback for old gitea instances
if(new Version(tinyDb.getString("giteaVersion")).less("1.13.0")) {
apiCall = false;
instanceUrl = tinyDb.getString("instanceUrlWithProtocol");
instanceUrl = instanceUrl.substring(0, instanceUrl.lastIndexOf("api/v1/"));
}
getPullDiffContent(instanceUrl, repoOwner, repoName, pullIndex, instanceToken, apiCall);
@ -139,17 +140,17 @@ public class FileDiffActivity extends BaseActivity {
}
else if(response.code() == 403) {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, getString(R.string.labelGeneralError));
Toasty.error(ctx, getString(R.string.labelGeneralError));
}
@ -166,14 +167,10 @@ public class FileDiffActivity extends BaseActivity {
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
onClickListener = view -> {
@Override
public void onClick(View view) {
getIntent().removeExtra("singleFileName");
finish();
}
getIntent().removeExtra("singleFileName");
finish();
};
}

View File

@ -8,6 +8,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.text.Spanned;
import android.text.method.ScrollingMovementMethod;
import android.util.Base64;
import android.util.Log;
@ -31,18 +32,35 @@ import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.fragments.BottomSheetFileViewerFragment;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.highlightjs.HighlightJsView;
import org.mian.gitnex.helpers.highlightjs.models.Theme;
import org.mian.gitnex.models.Files;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Collection;
import java.util.Collections;
import java.util.Objects;
import io.noties.markwon.AbstractMarkwonPlugin;
import io.noties.markwon.Markwon;
import io.noties.markwon.core.CorePlugin;
import io.noties.markwon.core.MarkwonTheme;
import io.noties.markwon.ext.strikethrough.StrikethroughPlugin;
import io.noties.markwon.ext.tables.TablePlugin;
import io.noties.markwon.ext.tasklist.TaskListPlugin;
import io.noties.markwon.html.HtmlPlugin;
import io.noties.markwon.image.DefaultMediaDecoder;
import io.noties.markwon.image.ImageItem;
import io.noties.markwon.image.ImagesPlugin;
import io.noties.markwon.image.SchemeHandler;
import io.noties.markwon.image.gif.GifMediaDecoder;
import io.noties.markwon.image.svg.SvgMediaDecoder;
import io.noties.markwon.linkify.LinkifyPlugin;
import retrofit2.Call;
import retrofit2.Callback;
@ -65,6 +83,10 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
private LinearLayout pdfViewFrame;
private byte[] decodedPdf;
private Boolean pdfNightMode;
private String singleFileName;
private String fileSha;
private AppUtil appUtil;
private TinyDB tinyDb;
@Override
protected int getLayoutResourceId() {
@ -77,12 +99,14 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
appUtil = new AppUtil();
tinyDb = new TinyDB(appCtx);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final TinyDB tinyDb = new TinyDB(appCtx);
String repoFullName = tinyDb.getString("repoFullName");
String repoBranch = tinyDb.getString("repoBranch");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
@ -90,6 +114,8 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
tinyDb.putBoolean("enableMarkdownInFileView", false);
ImageView closeActivity = findViewById(R.id.close);
singleFileContents = findViewById(R.id.singleFileContents);
singleCodeContents = findViewById(R.id.singleCodeContents);
@ -99,7 +125,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
pdfViewFrame = findViewById(R.id.pdfViewFrame);
singleFileContentsFrame = findViewById(R.id.singleFileContentsFrame);
String singleFileName = getIntent().getStringExtra("singleFileName");
singleFileName = getIntent().getStringExtra("singleFileName");
TextView toolbar_title = findViewById(R.id.toolbar_title);
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
@ -118,22 +144,40 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
}
catch(UnsupportedEncodingException e) {
assert singleFileName != null;
Log.i("singleFileName", singleFileName);
}
toolbar_title.setText(singleFileName);
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName);
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName, repoBranch);
}
private void getSingleFileContents(String instanceUrl, String token, final String owner, String repo, final String filename) {
@Override
public void onResume() {
final TinyDB tinyDb = new TinyDB(appCtx);
super.onResume();
Call<Files> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getSingleFileContents(token, owner, repo, filename);
String repoFullName = tinyDb.getString("repoFullName");
String repoBranch = tinyDb.getString("repoBranch");
String[] parts = repoFullName.split("/");
String repoOwner = parts[0];
String repoName = parts[1];
String instanceUrl = tinyDb.getString("instanceUrl");
String loginUid = tinyDb.getString("loginUid");
String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
if(tinyDb.getBoolean("fileModified")) {
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName, repoBranch);
tinyDb.putBoolean("fileModified", false);
}
}
private void getSingleFileContents(String instanceUrl, String token, final String owner, String repo, final String filename, String ref) {
Call<Files> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getSingleFileContents(token, owner, repo, filename, ref);
call.enqueue(new Callback<Files>() {
@ -142,7 +186,6 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
if(response.code() == 200) {
AppUtil appUtil = new AppUtil();
assert response.body() != null;
if(!response.body().getContent().equals("")) {
@ -150,6 +193,8 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
String fileExtension = FileUtils.getExtension(filename);
mProgressBar.setVisibility(View.GONE);
fileSha = response.body().getSha();
// download file meta
tinyDb.putString("downloadFileName", filename);
tinyDb.putString("downloadFileContents", response.body().getContent());
@ -246,17 +291,17 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
}
else if(response.code() == 403) {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, getString(R.string.labelGeneralError));
Toasty.error(ctx, getString(R.string.labelGeneralError));
}
@ -276,6 +321,13 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
inflater.inflate(R.menu.files_view_menu, menu);
String fileExtension = FileUtils.getExtension(singleFileName);
if(!fileExtension.equalsIgnoreCase("md")) {
menu.getItem(0).setVisible(false);
}
return true;
}
@ -286,11 +338,82 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
switch(id) {
case android.R.id.home:
finish();
return true;
case R.id.genericMenu:
BottomSheetFileViewerFragment bottomSheet = new BottomSheetFileViewerFragment();
bottomSheet.show(getSupportFragmentManager(), "fileViewerBottomSheet");
return true;
case R.id.markdown:
final Markwon markwon = Markwon.builder(Objects.requireNonNull(ctx)).usePlugin(CorePlugin.create())
.usePlugin(ImagesPlugin.create(plugin -> {
plugin.addSchemeHandler(new SchemeHandler() {
@NonNull
@Override
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
final int resourceId = ctx.getResources().getIdentifier(
raw.substring("drawable://".length()),
"drawable",
ctx.getPackageName());
final Drawable drawable = ctx.getDrawable(resourceId);
assert drawable != null;
return ImageItem.withResult(drawable);
}
@NonNull
@Override
public Collection<String> supportedSchemes() {
return Collections.singleton("drawable");
}
});
plugin.placeholderProvider(drawable -> null);
plugin.addMediaDecoder(GifMediaDecoder.create(false));
plugin.addMediaDecoder(SvgMediaDecoder.create(ctx.getResources()));
plugin.addMediaDecoder(SvgMediaDecoder.create());
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(ctx.getResources()));
plugin.defaultMediaDecoder(DefaultMediaDecoder.create());
}))
.usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
builder.codeTextColor(tinyDb.getInt("codeBlockColor")).codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
.linkColor(getResources().getColor(R.color.lightBlue));
}
})
.usePlugin(TablePlugin.create(ctx))
.usePlugin(TaskListPlugin.create(ctx))
.usePlugin(HtmlPlugin.create())
.usePlugin(StrikethroughPlugin.create())
.usePlugin(LinkifyPlugin.create())
.build();
if(!tinyDb.getBoolean("enableMarkdownInFileView")) {
singleCodeContents.setVisibility(View.GONE);
singleFileContentsFrame.setVisibility(View.VISIBLE);
singleFileContents.setVisibility(View.VISIBLE);
Spanned bodyWithMD = markwon.toMarkdown(appUtil.decodeBase64(tinyDb.getString("downloadFileContents")));
markwon.setParsedMarkdown(singleFileContents, bodyWithMD);
tinyDb.putBoolean("enableMarkdownInFileView", true);
}
else {
singleCodeContents.setVisibility(View.VISIBLE);
singleFileContentsFrame.setVisibility(View.GONE);
singleFileContents.setVisibility(View.GONE);
singleCodeContents.setSource(appUtil.decodeBase64(tinyDb.getString("downloadFileContents")));
tinyDb.putBoolean("enableMarkdownInFileView", false);
}
return true;
default:
return super.onOptionsItemSelected(item);
@ -304,15 +427,48 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
if("downloadFile".equals(text)) {
requestFileDownload();
}
if("deleteFile".equals(text)) {
String fileExtension = FileUtils.getExtension(singleFileName);
String data = appUtil.decodeBase64(tinyDb.getString("downloadFileContents"));
Intent intent = new Intent(ctx, CreateFileActivity.class);
intent.putExtra("fileAction", 1);
intent.putExtra("filePath", singleFileName);
intent.putExtra("fileSha", fileSha);
if(!appUtil.imageExtension(fileExtension)) {
intent.putExtra("fileContents", data);
}
else {
intent.putExtra("fileContents", "");
}
ctx.startActivity(intent);
}
if("editFile".equals(text)) {
String fileExtension = FileUtils.getExtension(singleFileName);
String data = appUtil.decodeBase64(tinyDb.getString("downloadFileContents"));
Intent intent = new Intent(ctx, CreateFileActivity.class);
intent.putExtra("fileAction", 2);
intent.putExtra("filePath", singleFileName);
intent.putExtra("fileSha", fileSha);
if(!appUtil.imageExtension(fileExtension)) {
intent.putExtra("fileContents", data);
}
else {
intent.putExtra("fileContents", "");
}
ctx.startActivity(intent);
}
}
private void requestFileDownload() {
final TinyDB tinyDb = new TinyDB(appCtx);
if(!tinyDb.getString("downloadFileContents").isEmpty()) {
int CREATE_REQUEST_CODE = 40;
@ -329,7 +485,8 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
}
else {
Toasty.error(ctx, getString(R.string.waitLoadingDownloadFile));
Toasty.warning(ctx, getString(R.string.waitLoadingDownloadFile));
}
}
@ -339,9 +496,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
super.onActivityResult(requestCode, resultCode, data);
final TinyDB tinyDb = new TinyDB(appCtx);
if (requestCode == 40 && resultCode == RESULT_OK) {
if(requestCode == 40 && resultCode == RESULT_OK) {
try {
@ -357,10 +512,11 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
outputStream.write(dataAsBytes);
outputStream.close();
Toasty.info(ctx, getString(R.string.downloadFileSaved));
Toasty.success(ctx, getString(R.string.downloadFileSaved));
}
catch (IOException e) {
catch(IOException e) {
Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
}
@ -374,8 +530,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
getIntent().removeExtra("singleFileName");
finish();
};
}
}
}

View File

@ -25,15 +25,14 @@ import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.amulyakhare.textdrawable.TextDrawable;
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton;
import com.vdurmont.emoji.EmojiParser;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.IssueCommentsAdapter;
@ -41,24 +40,23 @@ import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.fragments.BottomSheetSingleIssueFragment;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.ClickListener;
import org.mian.gitnex.helpers.ColorInverter;
import org.mian.gitnex.helpers.LabelWidthCalculator;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.UserMentions;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.IssueComments;
import org.mian.gitnex.models.Issues;
import org.mian.gitnex.models.WatchInfo;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.viewmodels.IssueCommentsViewModel;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import io.noties.markwon.AbstractMarkwonPlugin;
@ -99,7 +97,7 @@ public class IssueDetailActivity extends BaseActivity {
private HorizontalScrollView assigneesScrollView;
private ScrollView scrollViewComments;
private TextView issueModified;
private ImageView createNewComment;
private ExtendedFloatingActionButton createNewComment;
final Context ctx = this;
private Context appCtx;
private LinearLayout labelsLayout;
@ -191,7 +189,9 @@ public class IssueDetailActivity extends BaseActivity {
swipeRefresh.setOnRefreshListener(() -> new Handler().postDelayed(() -> {
swipeRefresh.setRefreshing(false);
IssueCommentsViewModel.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, ctx);
IssueCommentsViewModel
.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex,
ctx);
}, 500));
@ -265,7 +265,9 @@ public class IssueDetailActivity extends BaseActivity {
if(tinyDb.getBoolean("commentPosted")) {
scrollViewComments.post(() -> {
IssueCommentsViewModel.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, ctx);
IssueCommentsViewModel
.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex,
ctx);
new Handler().postDelayed(() -> scrollViewComments.fullScroll(ScrollView.FOCUS_DOWN), 1000);
@ -277,7 +279,9 @@ public class IssueDetailActivity extends BaseActivity {
if(tinyDb.getBoolean("commentEdited")) {
scrollViewComments.post(() -> {
IssueCommentsViewModel.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, ctx);
IssueCommentsViewModel
.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex,
ctx);
tinyDb.putBoolean("commentEdited", false);
});
@ -315,12 +319,11 @@ public class IssueDetailActivity extends BaseActivity {
IssueCommentsViewModel issueCommentsModel = new ViewModelProvider(this).get(IssueCommentsViewModel.class);
issueCommentsModel.getIssueCommentList(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), owner, repo, index, ctx).observe(this, new Observer<List<IssueComments>>() {
@Override
public void onChanged(@Nullable List<IssueComments> issueCommentsMain) {
issueCommentsModel.getIssueCommentList(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), owner, repo, index, ctx)
.observe(this, issueCommentsMain -> {
assert issueCommentsMain != null;
if(issueCommentsMain.size() > 0) {
divider.setVisibility(View.VISIBLE);
}
@ -328,15 +331,15 @@ public class IssueDetailActivity extends BaseActivity {
adapter = new IssueCommentsAdapter(ctx, issueCommentsMain);
mRecyclerView.setAdapter(adapter);
}
});
});
}
private void getSingleIssue(String instanceUrl, String instanceToken, String repoOwner, String repoName, int issueIndex, String loginUid) {
final TinyDB tinyDb = new TinyDB(appCtx);
Call<Issues> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
Call<Issues> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
.getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
call.enqueue(new Callback<Issues>() {
@ -348,52 +351,59 @@ public class IssueDetailActivity extends BaseActivity {
Issues singleIssue = response.body();
assert singleIssue != null;
final Markwon markwon = Markwon.builder(Objects.requireNonNull(ctx)).usePlugin(CorePlugin.create()).usePlugin(ImagesPlugin.create(plugin -> {
plugin.addSchemeHandler(new SchemeHandler() {
final Markwon markwon = Markwon.builder(Objects.requireNonNull(ctx)).usePlugin(CorePlugin.create())
.usePlugin(ImagesPlugin.create(plugin -> {
plugin.addSchemeHandler(new SchemeHandler() {
@NonNull
@Override
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
final int resourceId = ctx.getResources()
.getIdentifier(raw.substring("drawable://".length()), "drawable", ctx.getPackageName());
final Drawable drawable = ctx.getDrawable(resourceId);
assert drawable != null;
return ImageItem.withResult(drawable);
}
@NonNull
@Override
public Collection<String> supportedSchemes() {
return Collections.singleton("drawable");
}
});
plugin.placeholderProvider(drawable -> null);
plugin.addMediaDecoder(GifMediaDecoder.create(false));
plugin.addMediaDecoder(SvgMediaDecoder.create(ctx.getResources()));
plugin.addMediaDecoder(SvgMediaDecoder.create());
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(ctx.getResources()));
plugin.defaultMediaDecoder(DefaultMediaDecoder.create());
})).usePlugin(new AbstractMarkwonPlugin() {
@NonNull
@Override
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
final int resourceId = ctx.getResources().getIdentifier(raw.substring("drawable://".length()), "drawable", ctx.getPackageName());
final Drawable drawable = ctx.getDrawable(resourceId);
assert drawable != null;
return ImageItem.withResult(drawable);
builder.codeTextColor(tinyDb.getInt("codeBlockColor")).codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
.linkColor(getResources().getColor(R.color.lightBlue));
}
@NonNull
@Override
public Collection<String> supportedSchemes() {
return Collections.singleton("drawable");
}
});
plugin.placeholderProvider(drawable -> null);
plugin.addMediaDecoder(GifMediaDecoder.create(false));
plugin.addMediaDecoder(SvgMediaDecoder.create(ctx.getResources()));
plugin.addMediaDecoder(SvgMediaDecoder.create());
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(ctx.getResources()));
plugin.defaultMediaDecoder(DefaultMediaDecoder.create());
})).usePlugin(new AbstractMarkwonPlugin() {
@Override
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
builder.codeTextColor(tinyDb.getInt("codeBlockColor")).codeBackgroundColor(tinyDb.getInt("codeBlockBackground")).linkColor(getResources().getColor(R.color.lightBlue));
}
}).usePlugin(TablePlugin.create(ctx)).usePlugin(TaskListPlugin.create(ctx)).usePlugin(HtmlPlugin.create()).usePlugin(StrikethroughPlugin.create()).usePlugin(LinkifyPlugin.create()).build();
}).usePlugin(TablePlugin.create(ctx)).usePlugin(TaskListPlugin.create(ctx)).usePlugin(HtmlPlugin.create())
.usePlugin(StrikethroughPlugin.create()).usePlugin(LinkifyPlugin.create()).build();
TinyDB tinyDb = new TinyDB(appCtx);
final String locale = tinyDb.getString("locale");
final String timeFormat = tinyDb.getString("dateFormat");
tinyDb.putString("issueState", singleIssue.getState());
tinyDb.putString("issueTitle", singleIssue.getTitle());
tinyDb.putString("singleIssueHtmlUrl", singleIssue.getHtml_url());
PicassoService.getInstance(ctx).get().load(singleIssue.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(assigneeAvatar);
String issueNumber_ = "<font color='" + appCtx.getResources().getColor(R.color.lightGray) + "'>" + appCtx.getResources().getString(R.string.hash) + singleIssue.getNumber() + "</font>";
PicassoService.getInstance(ctx).get().load(singleIssue.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated)
.transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(assigneeAvatar);
String issueNumber_ = "<font color='" + appCtx.getResources().getColor(R.color.lightGray) + "'>" + appCtx.getResources()
.getString(R.string.hash) + singleIssue.getNumber() + "</font>";
issueTitle.setText(Html.fromHtml(issueNumber_ + " " + singleIssue.getTitle()));
String cleanIssueDescription = singleIssue.getBody().trim();
Spanned bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(cleanIssueDescription));
@ -410,15 +420,19 @@ public class IssueDetailActivity extends BaseActivity {
ImageView assigneesView = new ImageView(ctx);
PicassoService.getInstance(ctx).get().load(singleIssue.getAssignees().get(i).getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(100, 100).centerCrop().into(assigneesView);
PicassoService.getInstance(ctx).get().load(singleIssue.getAssignees().get(i).getAvatar_url())
.placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(100, 100).centerCrop()
.into(assigneesView);
assigneesLayout.addView(assigneesView);
assigneesView.setLayoutParams(params1);
if(!singleIssue.getAssignees().get(i).getFull_name().equals("")) {
assigneesView.setOnClickListener(new ClickListener(getString(R.string.assignedTo, singleIssue.getAssignees().get(i).getFull_name()), ctx));
assigneesView.setOnClickListener(
new ClickListener(getString(R.string.assignedTo, singleIssue.getAssignees().get(i).getFull_name()), ctx));
}
else {
assigneesView.setOnClickListener(new ClickListener(getString(R.string.assignedTo, singleIssue.getAssignees().get(i).getLogin()), ctx));
assigneesView.setOnClickListener(
new ClickListener(getString(R.string.assignedTo, singleIssue.getAssignees().get(i).getLogin()), ctx));
}
}
@ -427,12 +441,13 @@ public class IssueDetailActivity extends BaseActivity {
assigneesScrollView.setVisibility(View.GONE);
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 15, 0);
if(singleIssue.getLabels() != null) {
labelsScrollView.setVisibility(View.VISIBLE);
int width = 25;
for(int i = 0; i < singleIssue.getLabels().size(); i++) {
String labelColor = singleIssue.getLabels().get(i).getColor();
@ -444,9 +459,15 @@ public class IssueDetailActivity extends BaseActivity {
labelsLayout.setGravity(Gravity.START | Gravity.TOP);
labelsView.setLayoutParams(params);
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).textColor(new ColorInverter().getContrastColor(color)).fontSize(30).width(LabelWidthCalculator.calculateLabelWidth(labelName, Typeface.DEFAULT, 30, 15)).height(50).endConfig().buildRoundRect(labelName, color, 10);
labelsView.setImageDrawable(drawable);
int height = AppUtil.getPixelsFromDensity(ctx, 25);
int textSize = AppUtil.getPixelsFromScaledDensity(ctx, 15);
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT)
.textColor(new ColorInverter().getContrastColor(color)).fontSize(textSize)
.width(LabelWidthCalculator.calculateLabelWidth(labelName, Typeface.DEFAULT, textSize, AppUtil.getPixelsFromDensity(ctx, 10)))
.height(height).endConfig().buildRoundRect(labelName, color, AppUtil.getPixelsFromDensity(ctx, 5));
labelsView.setImageDrawable(drawable);
labelsLayout.addView(labelsView);
}
@ -461,7 +482,8 @@ public class IssueDetailActivity extends BaseActivity {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", new Locale(locale));
String dueDate = formatter.format(singleIssue.getDue_date());
issueDueDate.setText(dueDate);
issueDueDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getDue_date()), ctx));
issueDueDate
.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getDue_date()), ctx));
}
else if(timeFormat.equals("normal1")) {
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", new Locale(locale));
@ -481,7 +503,8 @@ public class IssueDetailActivity extends BaseActivity {
edited = getString(R.string.colorfulBulletSpan) + getString(R.string.modifiedText);
issueModified.setVisibility(View.VISIBLE);
issueModified.setText(edited);
issueModified.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getUpdated_at()), ctx));
issueModified
.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getUpdated_at()), ctx));
}
else {
issueModified.setVisibility(View.INVISIBLE);
@ -508,7 +531,8 @@ public class IssueDetailActivity extends BaseActivity {
issueCreatedTime.setVisibility(View.VISIBLE);
if(timeFormat.equals("pretty")) {
issueCreatedTime.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getCreated_at()), ctx));
issueCreatedTime
.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getCreated_at()), ctx));
}
if(singleIssue.getMilestone() != null) {
@ -519,10 +543,12 @@ public class IssueDetailActivity extends BaseActivity {
}
if(!singleIssue.getUser().getFull_name().equals("")) {
assigneeAvatar.setOnClickListener(new ClickListener(ctx.getResources().getString(R.string.issueCreator) + singleIssue.getUser().getFull_name(), ctx));
assigneeAvatar.setOnClickListener(
new ClickListener(ctx.getResources().getString(R.string.issueCreator) + singleIssue.getUser().getFull_name(), ctx));
}
else {
assigneeAvatar.setOnClickListener(new ClickListener(ctx.getResources().getString(R.string.issueCreator) + singleIssue.getUser().getLogin(), ctx));
assigneeAvatar.setOnClickListener(
new ClickListener(ctx.getResources().getString(R.string.issueCreator) + singleIssue.getUser().getLogin(), ctx));
}
progressBar.setVisibility(View.GONE);
@ -531,7 +557,10 @@ public class IssueDetailActivity extends BaseActivity {
else if(response.code() == 401) {
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle), getResources().getString(R.string.alertDialogTokenRevokedMessage), getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
@ -547,7 +576,8 @@ public class IssueDetailActivity extends BaseActivity {
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
Call<WatchInfo> call2 = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkIssueWatchStatus(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
Call<WatchInfo> call2 = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
.checkIssueWatchStatus(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
call2.enqueue(new Callback<WatchInfo>() {

View File

@ -2,7 +2,6 @@ package org.mian.gitnex.activities;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
@ -13,7 +12,6 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.NonNull;
@ -21,16 +19,18 @@ import androidx.appcompat.app.AlertDialog;
import com.tooltip.Tooltip;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.NetworkObserver;
import org.mian.gitnex.helpers.PathsHelper;
import org.mian.gitnex.helpers.SnackBar;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.UrlHelper;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.GiteaVersion;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.models.UserTokens;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.List;
@ -46,8 +46,9 @@ import retrofit2.Callback;
public class LoginActivity extends BaseActivity {
private enum Protocol { HTTPS, HTTP }
private enum LoginType { BASIC, TOKEN }
private enum Protocol {HTTPS, HTTP}
private enum LoginType {BASIC, TOKEN}
private Context appCtx;
private Context ctx = this;
@ -59,7 +60,6 @@ public class LoginActivity extends BaseActivity {
private TextView otpInfo;
private RadioGroup loginMethod;
private String device_id = "token";
private ScrollView layoutView;
@Override
protected int getLayoutResourceId() {
@ -86,7 +86,6 @@ public class LoginActivity extends BaseActivity {
protocolSpinner = findViewById(R.id.httpsSpinner);
loginMethod = findViewById(R.id.loginMethod);
loginTokenCode = findViewById(R.id.loginTokenCode);
layoutView = findViewById(R.id.loginForm);
((TextView) findViewById(R.id.appVersion)).setText(AppUtil.getAppVersion(appCtx));
@ -99,23 +98,20 @@ public class LoginActivity extends BaseActivity {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if(protocolSpinner.getSelectedItem() == Protocol.HTTP) {
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.protocolError));
Toasty.warning(ctx, getResources().getString(R.string.protocolError));
}
}
public void onNothingSelected(AdapterView<?> parent) {}
public void onNothingSelected(AdapterView<?> parent) {
}
});
info_button.setOnClickListener(view -> new Tooltip.Builder(view)
.setText(R.string.urlInfoTooltip)
.setTextColor(getResources().getColor(R.color.white))
.setBackgroundColor(getResources().getColor(R.color.tooltipBackground))
.setCancelable(true)
.setDismissOnClick(true)
.setPadding(30)
.setCornerRadius(R.dimen.tooltipCornor)
.setGravity(Gravity.BOTTOM).show());
info_button.setOnClickListener(
view -> new Tooltip.Builder(view).setText(R.string.urlInfoTooltip).setTextColor(getResources().getColor(R.color.colorWhite))
.setBackgroundColor(getResources().getColor(R.color.tooltipBackground)).setCancelable(true).setDismissOnClick(true).setPadding(30)
.setCornerRadius(R.dimen.tooltipCornor).setGravity(Gravity.BOTTOM).show());
loginMethod.setOnCheckedChangeListener((group, checkedId) -> {
@ -138,13 +134,12 @@ public class LoginActivity extends BaseActivity {
if(isAvailable) {
enableProcessButton();
SnackBar.success(ctx, layoutView, getResources().getString(R.string.netConnectionIsBack));
}
else {
disableProcessButton();
loginButton.setText(getResources().getString(R.string.btnLogin));
SnackBar.error(ctx, layoutView, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
}
});
@ -170,16 +165,12 @@ public class LoginActivity extends BaseActivity {
Protocol protocol = (Protocol) protocolSpinner.getSelectedItem();
LoginType loginType = (loginMethod.getCheckedRadioButtonId() == R.id.loginUsernamePassword) ? LoginType.BASIC : LoginType.TOKEN;
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET.getText().toString(), "http"))
.toUri();
URI rawInstanceUrl = UrlBuilder.fromString(UrlHelper.fixScheme(instanceUrlET.getText().toString(), "http")).toUri();
URI instanceUrlWithProtocol = UrlBuilder.fromUri(rawInstanceUrl)
.withPath(PathsHelper.join(rawInstanceUrl.getPath()))
.withScheme(protocol.name().toLowerCase())
.toUri();
URI instanceUrlWithProtocol = UrlBuilder.fromUri(rawInstanceUrl).withPath(PathsHelper.join(rawInstanceUrl.getPath()))
.withScheme(protocol.name().toLowerCase()).toUri();
URI instanceUrl = UrlBuilder.fromUri(instanceUrlWithProtocol)
.withPath(PathsHelper.join(instanceUrlWithProtocol.getPath(), "/api/v1/"))
URI instanceUrl = UrlBuilder.fromUri(instanceUrlWithProtocol).withPath(PathsHelper.join(instanceUrlWithProtocol.getPath(), "/api/v1/"))
.toUri();
tinyDB.putString("loginType", loginType.name().toLowerCase());
@ -189,7 +180,7 @@ public class LoginActivity extends BaseActivity {
if(instanceUrlET.getText().toString().equals("")) {
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.emptyFieldURL));
Toasty.error(ctx, getResources().getString(R.string.emptyFieldURL));
enableProcessButton();
return;
@ -199,7 +190,7 @@ public class LoginActivity extends BaseActivity {
if(otpCode.length() != 0 && otpCode.length() != 6) {
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.loginOTPTypeError));
Toasty.warning(ctx, getResources().getString(R.string.loginOTPTypeError));
enableProcessButton();
return;
@ -214,7 +205,7 @@ public class LoginActivity extends BaseActivity {
if(loginUid.equals("")) {
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.emptyFieldUsername));
Toasty.error(ctx, getResources().getString(R.string.emptyFieldUsername));
enableProcessButton();
return;
@ -222,7 +213,7 @@ public class LoginActivity extends BaseActivity {
if(loginPass.equals("")) {
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.emptyFieldPassword));
Toasty.error(ctx, getResources().getString(R.string.emptyFieldPassword));
enableProcessButton();
return;
@ -231,33 +222,35 @@ public class LoginActivity extends BaseActivity {
int loginOTP = (otpCode.length() > 0) ? Integer.parseInt(otpCode.getText().toString().trim()) : 0;
tinyDB.putString("loginUid", loginUid);
versionCheck(instanceUrl.toString(), loginUid, loginPass, loginOTP, loginToken, 1);
versionCheck(instanceUrl.toString(), loginUid, loginPass, loginOTP, loginToken, loginType);
}
else {
if(loginToken.equals("")) {
SnackBar.warning(ctx, layoutView, getResources().getString(R.string.loginTokenError));
Toasty.error(ctx, getResources().getString(R.string.loginTokenError));
enableProcessButton();
return;
}
versionCheck(instanceUrl.toString(), loginUid, loginPass, 123, loginToken, 2);
versionCheck(instanceUrl.toString(), loginUid, loginPass, 123, loginToken, loginType);
}
} catch (Exception e) {
}
catch(Exception e) {
Log.e("onFailure-login", e.toString());
SnackBar.error(ctx, layoutView, getResources().getString(R.string.malformedUrl));
Toasty.error(ctx, getResources().getString(R.string.malformedUrl));
enableProcessButton();
}
}
private void versionCheck(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP, final String loginToken, final int loginType) {
private void versionCheck(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP, final String loginToken,
final LoginType loginType) {
Call<GiteaVersion> callVersion;
@ -269,9 +262,9 @@ public class LoginActivity extends BaseActivity {
String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
callVersion = (loginOTP != 0) ?
RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithOTP(credential, loginOTP) :
RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithBasic(credential);
callVersion =
(loginOTP != 0) ? RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithOTP(credential, loginOTP) :
RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithBasic(credential);
}
@ -290,19 +283,17 @@ public class LoginActivity extends BaseActivity {
try {
gitea_version = new Version(version.getVersion());
}
catch(Error e) {
catch(Exception e) {
SnackBar.error(ctx, layoutView, getResources().getString(R.string.versionUnknown));
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
enableProcessButton();
return;
}
if(gitea_version.less(getString(R.string.versionLow))) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx)
.setTitle(getString(R.string.versionAlertDialogHeader))
.setMessage(getResources().getString(R.string.versionUnsupportedOld, version.getVersion()))
.setIcon(R.drawable.ic_warning)
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ctx).setTitle(getString(R.string.versionAlertDialogHeader))
.setMessage(getResources().getString(R.string.versionUnsupportedOld, version.getVersion())).setIcon(R.drawable.ic_warning)
.setCancelable(true);
alertDialogBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> {
@ -326,7 +317,7 @@ public class LoginActivity extends BaseActivity {
}
else {
SnackBar.info(ctx, layoutView, getResources().getString(R.string.versionUnsupportedNew));
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
}
@ -338,12 +329,15 @@ public class LoginActivity extends BaseActivity {
}
}
private void login(int loginType, String instanceUrl, String loginUid, String loginPass, int loginOTP, String loginToken) {
private void login(LoginType loginType, String instanceUrl, String loginUid, String loginPass, int loginOTP, String loginToken) {
if(loginType == 1) {
// ToDo: before store/create token: get UserInfo to check DB/AccountManager if there already exist a token
// the setup methods then can better handle all different cases
if(loginType == LoginType.BASIC) {
setup(instanceUrl, loginUid, loginPass, loginOTP);
}
else if(loginType == 2) { // Token
else if(loginType == LoginType.TOKEN) { // Token
setupUsingExistingToken(instanceUrl, loginToken);
}
}
@ -352,7 +346,7 @@ public class LoginActivity extends BaseActivity {
public void onFailure(@NonNull Call<GiteaVersion> callVersion, @NonNull Throwable t) {
Log.e("onFailure-versionCheck", t.toString());
SnackBar.error(ctx, layoutView, getResources().getString(R.string.errorOnLogin));
Toasty.error(ctx, getResources().getString(R.string.errorOnLogin));
enableProcessButton();
}
});
@ -360,9 +354,7 @@ public class LoginActivity extends BaseActivity {
private void setupUsingExistingToken(String instanceUrl, final String loginToken) {
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx)
.getApiInterface()
.getUserInfo("token " + loginToken);
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserInfo("token " + loginToken);
call.enqueue(new Callback<UserInfo>() {
@ -380,18 +372,36 @@ public class LoginActivity extends BaseActivity {
tinyDB.putString("loginUid", userDetails.getLogin());
tinyDB.putString("userLogin", userDetails.getUsername());
// insert new account to db if does not exist
String accountName = userDetails.getUsername() + "@" + instanceUrl;
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
int checkAccount = userAccountsApi.getCount(accountName);
long accountId;
if(checkAccount == 0) {
accountId = userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
tinyDB.putInt("currentActiveAccountId", (int) accountId);
}
else {
userAccountsApi.updateTokenByAccountName(accountName, loginToken);
UserAccount data = userAccountsApi.getAccountData(accountName);
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
}
enableProcessButton();
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
break;
case 401:
SnackBar.error(ctx, layoutView, getResources().getString(R.string.unauthorizedApiError));
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
enableProcessButton();
break;
default:
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + response.code());
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
enableProcessButton();
}
@ -402,7 +412,7 @@ public class LoginActivity extends BaseActivity {
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericError));
Toasty.error(ctx, getResources().getString(R.string.genericError));
enableProcessButton();
}
@ -413,19 +423,16 @@ public class LoginActivity extends BaseActivity {
private void setup(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP) {
final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
final String tokenName = "gitnex-app-" + device_id;
Call<List<UserTokens>> call;
if(loginOTP != 0) {
call = RetrofitClient.getInstance(instanceUrl, ctx)
.getApiInterface()
.getUserTokensWithOTP(credential, loginOTP, loginUid);
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserTokensWithOTP(credential, loginOTP, loginUid);
}
else {
call = RetrofitClient.getInstance(instanceUrl, ctx)
.getApiInterface()
.getUserTokens(credential, loginUid);
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserTokens(credential, loginUid);
}
call.enqueue(new Callback<List<UserTokens>>() {
@ -435,140 +442,110 @@ public class LoginActivity extends BaseActivity {
List<UserTokens> userTokens = response.body();
AppUtil appUtil = new AppUtil();
if(response.code() == 200) {
assert userTokens != null;
boolean setTokenFlag = false;
for(UserTokens t : userTokens) {
if(t.getName().equals(tokenName)) {
if(userTokens.size() > 0) { // FIXME This is in need of a refactor, but i don't understand what the code is used for.
// this app had created an token on this instance before
// -> since it looks like GitNex forgot the secret we have to delete it first
if(userTokens.get(0).getToken_last_eight() != null) {
Call<Void> delcall;
if(loginOTP != 0) {
for(int i = 0; i < userTokens.size(); i++) {
if(userTokens.get(i).getToken_last_eight().equals(tinyDB.getString(loginUid + "-token-last-eight"))) {
setTokenFlag = true;
break;
}
delcall = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
.deleteTokenWithOTP(credential, loginOTP, loginUid, t.getId());
}
}
else {
else {
for(int i = 0; i < userTokens.size(); i++) {
if(userTokens.get(i).getSha1().equals(tinyDB.getString(loginUid + "-token"))) {
setTokenFlag = true;
break;
}
delcall = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().deleteToken(credential, loginUid, t.getId());
}
}
}
delcall.enqueue(new Callback<Void>() {
if(tinyDB.getString(loginUid + "-token").isEmpty() || !setTokenFlag) {
@Override
public void onResponse(@NonNull Call<Void> delcall, @NonNull retrofit2.Response<Void> response) {
UserTokens createUserToken = new UserTokens("gitnex-app-" + device_id);
Call<UserTokens> callCreateToken;
if(response.code() == 204) {
if(loginOTP != 0) {
setupToken(instanceUrl, loginUid, loginPass, loginOTP, tokenName);
}
else {
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx)
.getApiInterface()
.createNewTokenWithOTP(credential, loginOTP, loginUid, createUserToken);
}
else {
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
enableProcessButton();
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx)
.getApiInterface()
.createNewToken(credential, loginUid, createUserToken);
}
callCreateToken.enqueue(new Callback<UserTokens>() {
@Override
public void onResponse(@NonNull Call<UserTokens> callCreateToken, @NonNull retrofit2.Response<UserTokens> responseCreate) {
if(responseCreate.code() == 201) {
UserTokens newToken = responseCreate.body();
assert newToken != null;
if(!newToken.getSha1().equals("")) {
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx)
.getApiInterface()
.getUserInfo("token " + newToken.getSha1());
call.enqueue(new Callback<UserInfo>() {
@Override
public void onResponse(@NonNull Call<UserInfo> call, @NonNull retrofit2.Response<UserInfo> response) {
UserInfo userDetails = response.body();
switch(response.code()) {
case 200:
assert userDetails != null;
tinyDB.remove("loginPass");
tinyDB.putBoolean("loggedInMode", true);
tinyDB.putString("userLogin", userDetails.getUsername());
tinyDB.putString(loginUid + "-token", newToken.getSha1());
tinyDB.putString(loginUid + "-token-last-eight", appUtil.getLastCharactersOfWord(newToken.getSha1(), 8));
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
break;
case 401:
SnackBar.error(ctx, layoutView, getResources().getString(R.string.unauthorizedApiError));
enableProcessButton();
break;
default:
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + response.code());
enableProcessButton();
}
}
@Override
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericError));
enableProcessButton();
}
});
}
}
else if(responseCreate.code() == 500) {
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + responseCreate.code());
@Override
public void onFailure(@NonNull Call<Void> delcall, @NonNull Throwable t) {
Log.e("onFailure-login", t.toString());
Toasty.error(ctx, getResources().getString(R.string.malformedJson));
enableProcessButton();
}
}
@Override
public void onFailure(@NonNull Call<UserTokens> createUserToken, @NonNull Throwable t) {
Log.e("onFailure-token", t.toString());
}
});
});
return;
}
}
else {
String instanceToken = "token " + tinyDB.getString(loginUid + "-token");
setupToken(instanceUrl, loginUid, loginPass, loginOTP, tokenName);
}
else {
Call<UserInfo> callGetUsername = RetrofitClient.getInstance(instanceUrl, ctx)
.getApiInterface()
.getUserInfo(instanceToken);
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
enableProcessButton();
callGetUsername.enqueue(new Callback<UserInfo>() {
}
}
@Override
public void onFailure(@NonNull Call<List<UserTokens>> call, @NonNull Throwable t) {
Log.e("onFailure-login", t.toString());
Toasty.error(ctx, getResources().getString(R.string.malformedJson));
enableProcessButton();
}
});
}
private void setupToken(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP, final String tokenName) {
final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
UserTokens createUserToken = new UserTokens(tokenName);
Call<UserTokens> callCreateToken;
if(loginOTP != 0) {
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
.createNewTokenWithOTP(credential, loginOTP, loginUid, createUserToken);
}
else {
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().createNewToken(credential, loginUid, createUserToken);
}
callCreateToken.enqueue(new Callback<UserTokens>() {
@Override
public void onResponse(@NonNull Call<UserTokens> callCreateToken, @NonNull retrofit2.Response<UserTokens> responseCreate) {
if(responseCreate.code() == 201) {
UserTokens newToken = responseCreate.body();
assert newToken != null;
if(!newToken.getSha1().equals("")) {
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
.getUserInfo("token " + newToken.getSha1());
call.enqueue(new Callback<UserInfo>() {
@Override
public void onResponse(@NonNull Call<UserInfo> call, @NonNull retrofit2.Response<UserInfo> response) {
@ -579,19 +556,41 @@ public class LoginActivity extends BaseActivity {
case 200:
assert userDetails != null;
tinyDB.putString("userLogin", userDetails.getUsername());
tinyDB.remove("loginPass");
tinyDB.putBoolean("loggedInMode", true);
tinyDB.putString("userLogin", userDetails.getUsername());
tinyDB.putString(loginUid + "-token", newToken.getSha1());
tinyDB.putString(loginUid + "-token-last-eight", newToken.getToken_last_eight());
// insert new account to db if does not exist
String accountName = userDetails.getUsername() + "@" + instanceUrl;
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
int checkAccount = userAccountsApi.getCount(accountName);
long accountId;
if(checkAccount == 0) {
accountId = userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), newToken.getSha1(), "");
tinyDB.putInt("currentActiveAccountId", (int) accountId);
}
else {
userAccountsApi.updateTokenByAccountName(accountName, newToken.getSha1());
UserAccount data = userAccountsApi.getAccountData(accountName);
tinyDB.putInt("currentActiveAccountId", data.getAccountId());
}
startActivity(new Intent(LoginActivity.this, MainActivity.class));
finish();
break;
case 401:
SnackBar.error(ctx, layoutView, getResources().getString(R.string.unauthorizedApiError));
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
enableProcessButton();
break;
default:
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + response.code());
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
enableProcessButton();
}
@ -602,33 +601,30 @@ public class LoginActivity extends BaseActivity {
public void onFailure(@NonNull Call<UserInfo> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericError));
Toasty.error(ctx, getResources().getString(R.string.genericError));
enableProcessButton();
}
});
}
}
else {
else if(responseCreate.code() == 500) {
SnackBar.error(ctx, layoutView, getResources().getString(R.string.genericApiStatusError) + response.code());
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + responseCreate.code());
enableProcessButton();
}
}
@Override
public void onFailure(@NonNull Call<List<UserTokens>> call, @NonNull Throwable t) {
Log.e("onFailure-login", t.toString());
SnackBar.error(ctx, layoutView, getResources().getString(R.string.malformedJson));
enableProcessButton();
public void onFailure(@NonNull Call<UserTokens> createUserToken, @NonNull Throwable t) {
Log.e("onFailure-token", t.toString());
}
});
}
private void loadDefaults() {
if(tinyDB.getString("loginType").equals(LoginType.BASIC.name().toLowerCase())) {
@ -663,26 +659,14 @@ public class LoginActivity extends BaseActivity {
private void disableProcessButton() {
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(8);
shape.setColor(getResources().getColor(R.color.hintColor));
loginButton.setText(R.string.processingText);
loginButton.setBackground(shape);
loginButton.setEnabled(false);
}
private void enableProcessButton() {
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(8);
shape.setColor(getResources().getColor(R.color.btnBackground));
loginButton.setText(R.string.btnLogin);
loginButton.setBackground(shape);
loginButton.setEnabled(true);
}
}

View File

@ -17,34 +17,47 @@ import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
import com.google.android.material.navigation.NavigationView;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.UserAccountsNavAdapter;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.fragments.AboutFragment;
import org.mian.gitnex.fragments.AdministrationFragment;
import org.mian.gitnex.fragments.BottomSheetDraftsFragment;
import org.mian.gitnex.fragments.DraftsFragment;
import org.mian.gitnex.fragments.ExploreRepositoriesFragment;
import org.mian.gitnex.fragments.MyRepositoriesFragment;
import org.mian.gitnex.fragments.NotificationsFragment;
import org.mian.gitnex.fragments.OrganizationsFragment;
import org.mian.gitnex.fragments.ProfileFragment;
import org.mian.gitnex.fragments.RepositoriesFragment;
import org.mian.gitnex.fragments.SettingsFragment;
import org.mian.gitnex.fragments.StarredRepositoriesFragment;
import org.mian.gitnex.fragments.UserAccountsFragment;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.ChangeLog;
import org.mian.gitnex.helpers.ColorInverter;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.GiteaVersion;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import eightbitlab.com.blurview.BlurView;
import eightbitlab.com.blurview.RenderScriptBlur;
@ -55,7 +68,7 @@ import retrofit2.Callback;
* Author M M Arif
*/
public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener {
public class MainActivity extends BaseActivity implements NavigationView.OnNavigationItemSelectedListener, BottomSheetDraftsFragment.BottomSheetListener {
private DrawerLayout drawer;
private BlurView blurView;
@ -83,7 +96,9 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
final TinyDB tinyDb = new TinyDB(appCtx);
tinyDb.putBoolean("noConnection", false);
//userAvatar = findViewById(R.id.userAvatar);
Intent mainIntent = getIntent();
String launchFragment = mainIntent.getStringExtra("launchFragment");
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
@ -113,6 +128,10 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
return;
}
if(tinyDb.getInt("currentActiveAccountId") <= 0) {
AlertDialogs.forceLogoutDialog(ctx, getResources().getString(R.string.forceLogoutDialogHeader), getResources().getString(R.string.forceLogoutDialogDescription), getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
Toolbar toolbar = findViewById(R.id.toolbar);
toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
@ -153,15 +172,24 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
else if(fragmentById instanceof ExploreRepositoriesFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
}
else if(fragmentById instanceof NotificationsFragment) {
toolbarTitle.setText(R.string.pageTitleNotifications);
}
else if(fragmentById instanceof ProfileFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
}
else if(fragmentById instanceof AboutFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleAbout));
}
else if(fragmentById instanceof DraftsFragment) {
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
}
else if(fragmentById instanceof AdministrationFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleAdministration));
}
else if(fragmentById instanceof UserAccountsFragment) {
toolbarTitle.setText(getResources().getString(R.string.pageTitleUserAccounts));
}
drawer = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view);
@ -169,7 +197,6 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
final View hView = navigationView.getHeaderView(0);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
toggle.getDrawerArrowDrawable().setColor(getResources().getColor(R.color.darkGreen));
drawer.addDrawerListener(toggle);
drawer.addDrawerListener(new DrawerLayout.DrawerListener() {
@ -177,8 +204,13 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
@Override
public void onDrawerOpened(@NonNull View drawerView) {
}
@Override
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
if(tinyDb.getBoolean("noConnection")) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
tinyDb.putBoolean("noConnection", false);
}
@ -193,11 +225,29 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
userAvatarBackground = hView.findViewById(R.id.userAvatarBackground);
navHeaderFrame = hView.findViewById(R.id.navHeaderFrame);
List<UserAccount> userAccountsList;
userAccountsList = new ArrayList<>();
UserAccountsApi userAccountsApi;
userAccountsApi = new UserAccountsApi(ctx);
RecyclerView navRecyclerViewUserAccounts = hView.findViewById(R.id.navRecyclerViewUserAccounts);
UserAccountsNavAdapter adapterUserAccounts;
adapterUserAccounts = new UserAccountsNavAdapter(ctx, userAccountsList, drawer, toolbarTitle);
userAccountsApi.getAllAccounts().observe((AppCompatActivity) ctx, userAccounts -> {
if(userAccounts.size() > 0) {
userAccountsList.addAll(userAccounts);
navRecyclerViewUserAccounts.setAdapter(adapterUserAccounts);
}
});
userEmail.setTypeface(myTypeface);
userFullName.setTypeface(myTypeface);
navigationView.getMenu().findItem(R.id.nav_administration).setVisible(tinyDb.getBoolean("userIsAdmin"));
if(!userEmailNav.equals("")) {
userEmail.setText(userEmailNav);
}
@ -248,10 +298,11 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
drawer.closeDrawers();
});
}
String currentVersion = tinyDb.getString("giteaVersion");
@Override
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {}
navigationView.getMenu().findItem(R.id.nav_administration).setVisible(tinyDb.getBoolean("userIsAdmin"));
navigationView.getMenu().findItem(R.id.nav_notifications).setVisible(new Version(currentVersion).higherOrEqual("1.12.3"));
}
@Override
public void onDrawerClosed(@NonNull View drawerView) {}
@ -262,9 +313,39 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
});
toggle.syncState();
toolbar.setNavigationIcon(R.drawable.ic_menu);
if(launchFragment != null) {
mainIntent.removeExtra("launchFragment");
switch(launchFragment) {
case "drafts":
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new DraftsFragment()).commit();
navigationView.setCheckedItem(R.id.nav_comments_draft);
return;
case "notifications":
toolbarTitle.setText(getResources().getString(R.string.pageTitleNotifications));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
navigationView.setCheckedItem(R.id.nav_notifications);
return;
}
}
if(savedInstanceState == null) {
if(!new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.3")) {
if(tinyDb.getInt("homeScreenId") == 7) {
tinyDb.putInt("homeScreenId", 0);
}
}
switch(tinyDb.getInt("homeScreenId")) {
case 1:
@ -291,6 +372,24 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
navigationView.setCheckedItem(R.id.nav_profile);
break;
case 5:
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreRepositoriesFragment()).commit();
navigationView.setCheckedItem(R.id.nav_explore);
break;
case 6:
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new DraftsFragment()).commit();
navigationView.setCheckedItem(R.id.nav_comments_draft);
break;
case 7:
toolbarTitle.setText(getResources().getString(R.string.pageTitleNotifications));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
navigationView.setCheckedItem(R.id.nav_notifications);
break;
default:
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyRepositoriesFragment()).commit();
@ -298,13 +397,12 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
break;
}
}
if(!connToInternet) {
if(!tinyDb.getBoolean("noConnection")) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
}
tinyDb.putBoolean("noConnection", true);
@ -320,25 +418,67 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
// Changelog popup
int versionCode = 0;
try {
PackageInfo packageInfo = appCtx.getPackageManager().getPackageInfo(appCtx.getPackageName(), 0);
versionCode = packageInfo.versionCode;
}
catch(PackageManager.NameNotFoundException e) {
Log.e("changelogDialog", Objects.requireNonNull(e.getMessage()));
}
if(versionCode > tinyDb.getInt("versionCode")) {
tinyDb.putInt("versionCode", versionCode);
tinyDb.putBoolean("versionFlag", true);
ChangeLog changelogDialog = new ChangeLog(this);
changelogDialog.showDialog();
}
}
public void setActionBarTitle(@NonNull String title) {
@Override
public void onButtonClicked(String text) {
TinyDB tinyDb = new TinyDB(ctx);
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
if("deleteDrafts".equals(text)) {
if(currentActiveAccountId > 0) {
FragmentManager fm = getSupportFragmentManager();
DraftsFragment frag = (DraftsFragment) fm.findFragmentById(R.id.fragment_container);
if(frag != null) {
new AlertDialog.Builder(ctx)
.setTitle(R.string.deleteAllDrafts)
.setIcon(R.drawable.ic_delete)
.setCancelable(false)
.setMessage(R.string.deleteAllDraftsDialogMessage)
.setPositiveButton(R.string.menuDeleteText, (dialog, which) -> {
frag.deleteAllDrafts(currentActiveAccountId);
dialog.dismiss();
})
.setNeutralButton(R.string.cancelButton, null).show();
}
else {
Toasty.error(ctx, getResources().getString(R.string.genericError));
}
}
else {
Toasty.error(ctx, getResources().getString(R.string.genericError));
}
}
Objects.requireNonNull(getSupportActionBar()).setTitle(title);
}
@Override
@ -407,6 +547,16 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreRepositoriesFragment()).commit();
break;
case R.id.nav_notifications:
toolbarTitle.setText(R.string.pageTitleNotifications);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
break;
case R.id.nav_comments_draft:
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new DraftsFragment()).commit();
break;
case R.id.nav_administration:
toolbarTitle.setText(getResources().getString(R.string.pageTitleAdministration));
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AdministrationFragment()).commit();
@ -440,6 +590,21 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id == R.id.genericMenu) {
BottomSheetDraftsFragment bottomSheet = new BottomSheetDraftsFragment();
bottomSheet.show(getSupportFragmentManager(), "draftsBottomSheet");
return true;
}
return super.onOptionsItemSelected(item);
}
private void giteaVersion(final String instanceUrl) {
final TinyDB tinyDb = new TinyDB(appCtx);
@ -461,14 +626,12 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
tinyDb.putString("giteaVersion", version.getVersion());
}
}
@Override
public void onFailure(@NonNull Call<GiteaVersion> callVersion, @NonNull Throwable t) {
Log.e("onFailure-version", t.toString());
}
});
@ -527,7 +690,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
else {
String toastError = getResources().getString(R.string.genericApiStatusError) + response.code();
Toasty.info(ctx, toastError);
Toasty.error(ctx, toastError);
}

View File

@ -16,14 +16,14 @@ import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.databinding.ActivityMergePullRequestBinding;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.Collaborators;
import org.mian.gitnex.models.MergePullRequest;
import org.mian.gitnex.models.MergePullRequestSpinner;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import okhttp3.ResponseBody;
@ -126,12 +126,10 @@ public class MergePullRequestActivity extends BaseActivity {
if(!connToInternet) {
disableProcessButton();
}
else {
viewBinding.mergeButton.setOnClickListener(mergePullRequest);
}
}
@ -221,7 +219,7 @@ public class MergePullRequestActivity extends BaseActivity {
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
@ -266,7 +264,7 @@ public class MergePullRequestActivity extends BaseActivity {
deleteBranchFunction(repoOwner, repoName);
Toasty.info(ctx, getString(R.string.mergePRSuccessMsg));
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
tinyDb.putBoolean("prMerged", true);
tinyDb.putBoolean("resumePullRequests", true);
finish();
@ -281,7 +279,7 @@ public class MergePullRequestActivity extends BaseActivity {
deleteBranchFunction(repoOwner, repoName);
Toasty.info(ctx, getString(R.string.mergePRSuccessMsg));
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
tinyDb.putBoolean("prMerged", true);
tinyDb.putBoolean("resumePullRequests", true);
finish();
@ -291,7 +289,7 @@ public class MergePullRequestActivity extends BaseActivity {
}
else {
Toasty.info(ctx, getString(R.string.mergePRSuccessMsg));
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
tinyDb.putBoolean("prMerged", true);
tinyDb.putBoolean("resumePullRequests", true);
finish();
@ -308,13 +306,13 @@ public class MergePullRequestActivity extends BaseActivity {
else if(response.code() == 404) {
enableProcessButton();
Toasty.info(ctx, getString(R.string.mergePR404ErrorMsg));
Toasty.warning(ctx, getString(R.string.mergePR404ErrorMsg));
}
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.genericError));
Toasty.error(ctx, getString(R.string.genericError));
}
@ -373,15 +371,11 @@ public class MergePullRequestActivity extends BaseActivity {
private void disableProcessButton() {
viewBinding.mergeButton.setEnabled(false);
viewBinding.mergeButton.setBackground(getResources().getDrawable(R.drawable.shape_buttons_disabled));
}
private void enableProcessButton() {
viewBinding.mergeButton.setEnabled(true);
viewBinding.mergeButton.setBackground(getResources().getDrawable(R.drawable.shape_buttons));
}
}

View File

@ -7,8 +7,8 @@ import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.PathsHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.util.TinyDB;
import java.net.URI;
import java.net.URISyntaxException;
import io.mikael.urlbuilder.UrlBuilder;
@ -30,7 +30,9 @@ public class OpenRepoInBrowserActivity extends AppCompatActivity {
try {
URI instanceUrl = new URI(tinyDb.getString("instanceUrlWithProtocol"));
URI instanceUrl = new URI(UrlBuilder.fromString(tinyDb.getString("instanceUrl"))
.withPath("/")
.toString());
String browserPath = PathsHelper.join(instanceUrl.getPath(), getIntent().getStringExtra("repoFullNameBrowser"));

View File

@ -1,12 +1,7 @@
package org.mian.gitnex.activities;
import com.google.android.material.tabs.TabLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
@ -17,14 +12,23 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.tabs.TabLayout;
import org.mian.gitnex.R;
import org.mian.gitnex.fragments.MembersByOrgFragment;
import org.mian.gitnex.fragments.BottomSheetOrganizationFragment;
import org.mian.gitnex.fragments.MembersByOrgFragment;
import org.mian.gitnex.fragments.OrganizationInfoFragment;
import org.mian.gitnex.fragments.RepositoriesByOrgFragment;
import org.mian.gitnex.fragments.TeamsByOrgFragment;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import java.util.Objects;
import io.mikael.urlbuilder.UrlBuilder;
/**
* Author M M Arif
@ -34,6 +38,7 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
final Context ctx = this;
private Context appCtx;
private TinyDB tinyDb;
@Override
protected int getLayoutResourceId(){
@ -45,6 +50,7 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
tinyDb = new TinyDB(appCtx);
TinyDB tinyDb = new TinyDB(appCtx);
String orgName = tinyDb.getString("orgName");
@ -105,6 +111,7 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.repo_dotted_menu, menu);
return true;
@ -132,19 +139,28 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
@Override
public void onButtonClicked(String text) {
TinyDB tinyDb = new TinyDB(appCtx);
switch (text) {
case "repository":
tinyDb.putBoolean("organizationAction", true);
startActivity(new Intent(OrganizationDetailActivity.this, CreateRepoActivity.class));
break;
case "team":
startActivity(new Intent(OrganizationDetailActivity.this, CreateTeamByOrgActivity.class));
break;
}
//Log.i("clicked", text);
case "copyOrgUrl":
String url = UrlBuilder.fromString(tinyDb.getString("instanceUrl"))
.withPath("/")
.toString();
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("orgUrl", url + tinyDb.getString("orgName"));
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
break;
}
}
public class SectionsPagerAdapter extends FragmentPagerAdapter {
@ -157,7 +173,6 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
@Override
public Fragment getItem(int position) {
TinyDB tinyDb = new TinyDB(appCtx);
String orgName;
if(getIntent().getStringExtra("orgName") != null || !Objects.equals(getIntent().getStringExtra("orgName"), "")) {
orgName = getIntent().getStringExtra("orgName");

View File

@ -9,6 +9,7 @@ import android.view.MenuItem;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import androidx.lifecycle.ViewModelProvider;
@ -16,7 +17,7 @@ import org.mian.gitnex.R;
import org.mian.gitnex.adapters.TeamMembersByOrgAdapter;
import org.mian.gitnex.fragments.BottomSheetOrganizationTeamsFragment;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.viewmodels.TeamMembersByOrgViewModel;
import java.util.Objects;
@ -30,6 +31,7 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
private View.OnClickListener onClickListener;
private TeamMembersByOrgAdapter adapter;
private GridView mGridView;
private ProgressBar progressBar;
final Context ctx = this;
private Context appCtx;
@ -58,6 +60,7 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
TextView toolbarTitle = findViewById(R.id.toolbar_title);
noDataMembers = findViewById(R.id.noDataMembers);
mGridView = findViewById(R.id.gridView);
progressBar = findViewById(R.id.progressBar);
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
@ -114,6 +117,7 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
noDataMembers.setVisibility(View.VISIBLE);
}
progressBar.setVisibility(View.GONE);
});
}

View File

@ -1,10 +1,6 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.util.Log;
import android.util.Patterns;
@ -13,18 +9,21 @@ import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import com.google.gson.JsonElement;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.AddEmail;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
@ -67,11 +66,9 @@ public class ProfileEmailActivity extends BaseActivity {
if(!connToInternet) {
disableProcessButton();
} else {
addEmailButton.setOnClickListener(addEmailListener);
}
}
@ -94,20 +91,20 @@ public class ProfileEmailActivity extends BaseActivity {
if(!connToInternet) {
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if(newUserEmail.equals("")) {
Toasty.info(ctx, getString(R.string.emailErrorEmpty));
Toasty.error(ctx, getString(R.string.emailErrorEmpty));
return;
}
else if(!Patterns.EMAIL_ADDRESS.matcher(newUserEmail).matches()) {
Toasty.info(ctx, getString(R.string.emailErrorInvalid));
Toasty.warning(ctx, getString(R.string.emailErrorInvalid));
return;
}
@ -138,7 +135,7 @@ public class ProfileEmailActivity extends BaseActivity {
if(response.code() == 201) {
Toasty.info(ctx, getString(R.string.emailAddedText));
Toasty.success(ctx, getString(R.string.emailAddedText));
tinyDb.putBoolean("emailsRefresh", true);
enableProcessButton();
finish();
@ -156,25 +153,25 @@ public class ProfileEmailActivity extends BaseActivity {
else if(response.code() == 403) {
enableProcessButton();
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
enableProcessButton();
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else if(response.code() == 422) {
enableProcessButton();
Toasty.info(ctx, ctx.getString(R.string.emailErrorInUse));
Toasty.warning(ctx, ctx.getString(R.string.emailErrorInUse));
}
else {
enableProcessButton();
Toasty.info(ctx, getString(R.string.labelGeneralError));
Toasty.error(ctx, getString(R.string.labelGeneralError));
}
@ -190,32 +187,18 @@ public class ProfileEmailActivity extends BaseActivity {
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
onClickListener = view -> finish();
}
private void disableProcessButton() {
addEmailButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
addEmailButton.setBackground(shape);
}
private void enableProcessButton() {
addEmailButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
addEmailButton.setBackground(shape);
}
}

View File

@ -1,33 +1,42 @@
package org.mian.gitnex.activities;
import androidx.annotation.NonNull;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.Toolbar;
import com.hendraanggrian.appcompat.socialview.Mention;
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
import com.hendraanggrian.appcompat.widget.SocialAutoCompleteTextView;
import org.mian.gitnex.R;
import org.mian.gitnex.actions.IssueActions;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.DraftsApi;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Collaborators;
import org.mian.gitnex.models.Issues;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
@ -35,264 +44,383 @@ import java.util.List;
public class ReplyToIssueActivity extends BaseActivity {
public ImageView closeActivity;
private View.OnClickListener onClickListener;
public ImageView closeActivity;
private View.OnClickListener onClickListener;
final Context ctx = this;
private Context appCtx;
final Context ctx = this;
private Context appCtx;
private SocialAutoCompleteTextView addComment;
private ArrayAdapter<Mention> defaultMentionAdapter;
private Button replyButton;
private TextView draftSaved;
private SocialAutoCompleteTextView addComment;
private ArrayAdapter<Mention> defaultMentionAdapter;
private Button replyButton;
private String TAG = StaticGlobalVariables.replyToIssueActivity;
private long draftIdOnCreate;
@Override
protected int getLayoutResourceId(){
return R.layout.activity_reply_to_issue;
}
@Override
protected int getLayoutResourceId(){
return R.layout.activity_reply_to_issue;
}
@Override
public void onCreate(Bundle savedInstanceState) {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
TinyDB tinyDb = new TinyDB(appCtx);
addComment = findViewById(R.id.addComment);
addComment.setShowSoftInputOnFocus(true);
draftSaved = findViewById(R.id.draftSaved);
addComment = findViewById(R.id.addComment);
addComment.setShowSoftInputOnFocus(true);
defaultMentionAdapter = new MentionArrayAdapter<>(ctx);
loadCollaboratorsList();
loadCollaboratorsList();
addComment.setMentionAdapter(defaultMentionAdapter);
addComment.setMentionAdapter(defaultMentionAdapter);
closeActivity = findViewById(R.id.close);
TextView toolbar_title = findViewById(R.id.toolbar_title);
closeActivity = findViewById(R.id.close);
TextView toolbar_title = findViewById(R.id.toolbar_title);
addComment.requestFocus();
assert imm != null;
imm.showSoftInput(addComment, InputMethodManager.SHOW_IMPLICIT);
addComment.requestFocus();
assert imm != null;
imm.showSoftInput(addComment, InputMethodManager.SHOW_IMPLICIT);
if(!tinyDb.getString("issueTitle").isEmpty()) {
toolbar_title.setText(tinyDb.getString("issueTitle"));
}
if(!tinyDb.getString("issueTitle").isEmpty()) {
toolbar_title.setText(tinyDb.getString("issueTitle"));
}
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
replyButton = findViewById(R.id.replyButton);
if(getIntent().getStringExtra("draftId") != null) {
if(getIntent().getStringExtra("commentBody") != null) {
draftIdOnCreate = Long.parseLong(Objects.requireNonNull(getIntent().getStringExtra("draftId")));
}
else {
addComment.setText(getIntent().getStringExtra("commentBody"));
draftIdOnCreate = returnDraftId();
}
if(getIntent().getBooleanExtra("cursorToEnd", false)) {
addComment.setSelection(addComment.length());
}
replyButton = findViewById(R.id.replyButton);
}
if(getIntent().getStringExtra("commentBody") != null) {
if(getIntent().getStringExtra("commentAction") != null && getIntent().getStringExtra("commentAction").equals("edit")) {
addComment.setText(getIntent().getStringExtra("commentBody"));
final String commentId = getIntent().getStringExtra("commentId");
if(getIntent().getBooleanExtra("cursorToEnd", false)) {
addComment.setSelection(addComment.length());
}
toolbar_title.setText(getResources().getString(R.string.editCommentTitle));
replyButton.setText(getResources().getString(R.string.editCommentButtonText));
}
replyButton.setOnClickListener(v -> {
disableProcessButton();
IssueActions.editIssueComment(ctx, Integer.parseInt(commentId), addComment.getText().toString());
});
if(getIntent().getStringExtra("draftTitle") != null) {
return;
toolbar_title.setText(getIntent().getStringExtra("draftTitle"));
}
}
if(!connToInternet) {
if(getIntent().getStringExtra("commentAction") != null && Objects.equals(getIntent().getStringExtra("commentAction"), "edit") && !Objects.equals(getIntent().getStringExtra("commentId"), "new")) {
disableProcessButton();
final String commentId = getIntent().getStringExtra("commentId");
} else {
toolbar_title.setText(getResources().getString(R.string.editCommentTitle));
replyButton.setText(getResources().getString(R.string.editCommentButtonText));
replyButton.setOnClickListener(replyToIssue);
addComment.addTextChangedListener(new TextWatcher() {
}
public void afterTextChanged(Editable s) {
}
}
public void loadCollaboratorsList() {
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
final TinyDB tinyDb = new TinyDB(appCtx);
}
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
public void onTextChanged(CharSequence s, int start, int before, int count) {
Call<List<Collaborators>> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
saveDraft(addComment.getText().toString(), commentId, draftIdOnCreate);
draftSaved.setVisibility(View.VISIBLE);
call.enqueue(new Callback<List<Collaborators>>() {
}
@Override
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
});
if (response.isSuccessful()) {
replyButton.setOnClickListener(v -> {
assert response.body() != null;
String fullName = "";
for (int i = 0; i < response.body().size(); i++) {
if(!response.body().get(i).getFull_name().equals("")) {
fullName = response.body().get(i).getFull_name();
}
defaultMentionAdapter.add(
new Mention(response.body().get(i).getUsername(), fullName, response.body().get(i).getAvatar_url()));
}
disableProcessButton();
assert commentId != null;
IssueActions.editIssueComment(ctx, Integer.parseInt(commentId), addComment.getText().toString(), draftIdOnCreate);
} else {
});
Log.i("onResponse", String.valueOf(response.code()));
return;
}
}
}
addComment.addTextChangedListener(new TextWatcher() {
@Override
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
Log.i("onFailure", t.getMessage());
}
public void afterTextChanged(Editable s) {
});
}
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
private View.OnClickListener replyToIssue = new View.OnClickListener() {
public void onClick(View v) {
processNewCommentReply();
}
};
}
private void processNewCommentReply() {
public void onTextChanged(CharSequence s, int start, int before, int count) {
String newReplyDT = addComment.getText().toString();
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
saveDraft(addComment.getText().toString(), "new", draftIdOnCreate);
draftSaved.setVisibility(View.VISIBLE);
if(!connToInternet) {
}
Toasty.info(ctx, getResources().getString(R.string.checkNetConnection));
return;
});
}
if(!connToInternet) {
if(newReplyDT.equals("")) {
disableProcessButton();
Toasty.info(ctx, getString(R.string.commentEmptyError));
}
else {
}
else {
replyButton.setOnClickListener(replyToIssue);
disableProcessButton();
replyComment(newReplyDT);
}
}
}
}
private void saveDraft(String draftText, String commentId, long draftIdOnCreate) {
private void replyComment(String newReplyDT) {
TinyDB tinyDb = new TinyDB(getApplicationContext());
final TinyDB tinyDb = new TinyDB(appCtx);
int repositoryId = (int) tinyDb.getLong("repositoryId", 0);
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
int issueNumber = Integer.parseInt(tinyDb.getString("issueNumber"));
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
DraftsApi draftsApi = new DraftsApi(appCtx);
Issues issueComment = new Issues(newReplyDT);
if(draftIdOnCreate == 0) {
Call<Issues> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.replyCommentToIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, issueComment);
draftsApi.insertDraft(repositoryId, currentActiveAccountId, issueNumber, draftText, StaticGlobalVariables.draftTypeComment, commentId);
}
else {
call.enqueue(new Callback<Issues>() {
DraftsApi.updateDraft(draftText, (int) draftIdOnCreate, commentId); //updateDraftByIssueIdAsyncTask(draftText, issueNumber, repositoryId, commentId);
}
@Override
public void onResponse(@NonNull Call<Issues> call, @NonNull retrofit2.Response<Issues> response) {
}
if(response.code() == 201) {
private long returnDraftId() {
Toasty.info(ctx, getString(R.string.commentSuccess));
tinyDb.putBoolean("commentPosted", true);
tinyDb.putBoolean("resumeIssues", true);
tinyDb.putBoolean("resumePullRequests", true);
finish();
TinyDB tinyDb = new TinyDB(getApplicationContext());
}
else if(response.code() == 401) {
int repositoryId = (int) tinyDb.getLong("repositoryId", 0);
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
int issueNumber = Integer.parseInt(tinyDb.getString("issueNumber"));
enableProcessButton();
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
DraftsApi draftsApi = new DraftsApi(appCtx);
}
else {
return draftsApi.insertDraft(repositoryId, currentActiveAccountId, issueNumber, "", StaticGlobalVariables.draftTypeComment, "");
enableProcessButton();
Toasty.info(ctx, getString(R.string.commentError));
}
}
public void loadCollaboratorsList() {
}
final TinyDB tinyDb = new TinyDB(appCtx);
@Override
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
enableProcessButton();
}
});
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
}
Call<List<Collaborators>> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
private void disableProcessButton() {
call.enqueue(new Callback<List<Collaborators>>() {
replyButton.setEnabled(false);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.hintColor));
replyButton.setBackground(shape);
@Override
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
}
if (response.isSuccessful()) {
private void enableProcessButton() {
assert response.body() != null;
String fullName = "";
for(int i = 0; i < response.body().size(); i++) {
if(!response.body().get(i).getFull_name().equals("")) {
fullName = response.body().get(i).getFull_name();
}
defaultMentionAdapter.add(new Mention(response.body().get(i).getUsername(), fullName, response.body().get(i).getAvatar_url()));
}
replyButton.setEnabled(true);
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius( 8 );
shape.setColor(getResources().getColor(R.color.btnBackground));
replyButton.setBackground(shape);
}
else {
}
Log.i(TAG, String.valueOf(response.code()));
}
}
@Override
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
Log.e(TAG, t.toString());
}
});
}
private void initCloseListener() {
onClickListener = view -> finish();
}
private View.OnClickListener replyToIssue = v -> processNewCommentReply();
private void processNewCommentReply() {
String newReplyDT = addComment.getText().toString();
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
if(!connToInternet) {
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
return;
}
if(newReplyDT.equals("")) {
Toasty.error(ctx, getString(R.string.commentEmptyError));
}
else {
disableProcessButton();
replyComment(newReplyDT);
}
}
private void replyComment(String newReplyDT) {
final TinyDB tinyDb = new TinyDB(appCtx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullName = tinyDb.getString("repoFullName");
String[] parts = repoFullName.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
Issues issueComment = new Issues(newReplyDT);
Call<Issues> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.replyCommentToIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, issueComment);
call.enqueue(new Callback<Issues>() {
@Override
public void onResponse(@NonNull Call<Issues> call, @NonNull retrofit2.Response<Issues> response) {
if(response.code() == 201) {
Toasty.success(ctx, getString(R.string.commentSuccess));
tinyDb.putBoolean("commentPosted", true);
tinyDb.putBoolean("resumeIssues", true);
tinyDb.putBoolean("resumePullRequests", true);
// delete draft comment
if(tinyDb.getBoolean("draftsCommentsDeletionEnabled")) {
DraftsApi draftsApi = new DraftsApi(appCtx);
draftsApi.deleteSingleDraft((int) draftIdOnCreate);
}
finish();
}
else if(response.code() == 401) {
enableProcessButton();
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
getResources().getString(R.string.alertDialogTokenRevokedMessage),
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
}
else {
enableProcessButton();
Toasty.error(ctx, getString(R.string.commentError));
}
}
@Override
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
Log.e(TAG, t.toString());
enableProcessButton();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.reply_to_issue, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.replyToIssueMenu:
Intent fragmentIntent = new Intent(ReplyToIssueActivity.this, MainActivity.class);
fragmentIntent.putExtra("launchFragment", "drafts");
ReplyToIssueActivity.this.startActivity(fragmentIntent);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
private void disableProcessButton() {
replyButton.setEnabled(false);
}
private void enableProcessButton() {
replyButton.setEnabled(true);
}
}

View File

@ -1,7 +1,10 @@
package org.mian.gitnex.activities;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Typeface;
@ -16,6 +19,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@ -39,13 +43,18 @@ import org.mian.gitnex.fragments.PullRequestsFragment;
import org.mian.gitnex.fragments.ReleasesFragment;
import org.mian.gitnex.fragments.RepoInfoFragment;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.Branches;
import org.mian.gitnex.models.UserRepositories;
import org.mian.gitnex.models.WatchInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
@ -61,6 +70,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
private FragmentRefreshListener fragmentRefreshListener;
private FragmentRefreshListenerPr fragmentRefreshListenerPr;
private FragmentRefreshListenerMilestone fragmentRefreshListenerMilestone;
private FragmentRefreshListenerFiles fragmentRefreshListenerFiles;
private final Context ctx = this;
private Context appCtx;
@ -74,6 +84,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
private String repositoryOwner;
private String repositoryName;
public static ViewPager mViewPager;
private int tabsCount;
@Override
@ -165,7 +176,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
}
ViewPager mViewPager = findViewById(R.id.container);
mViewPager = findViewById(R.id.container);
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
@ -285,6 +296,10 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
filterMilestoneBottomSheet.show(getSupportFragmentManager(), "repoFilterMenuMilestoneBottomSheet");
return true;
case R.id.switchBranches:
chooseBranch();
return true;
default:
return super.onOptionsItemSelected(item);
@ -313,6 +328,10 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
startActivity(new Intent(RepoDetailActivity.this, AddCollaboratorToRepositoryActivity.class));
break;
case "chooseBranch":
chooseBranch();
break;
case "createRelease":
startActivity(new Intent(RepoDetailActivity.this, CreateReleaseActivity.class));
break;
@ -330,6 +349,14 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
startActivity(Intent.createChooser(sharingIntent, tinyDB.getString("repoHtmlUrl")));
break;
case "copyRepoUrl":
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("repoUrl", tinyDB.getString("repoHtmlUrl"));
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
break;
case "newFile":
startActivity(new Intent(RepoDetailActivity.this, CreateFileActivity.class));
break;
@ -374,6 +401,66 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
}
private void chooseBranch() {
Call<List<Branches>> call = RetrofitClient.getInstance(instanceUrl, ctx)
.getApiInterface()
.getBranches(instanceToken, repositoryOwner, repositoryName);
call.enqueue(new Callback<List<Branches>>() {
@Override
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull Response<List<Branches>> response) {
if(response.code() == 200) {
List<String> branchesList = new ArrayList<>();
int selectedBranch = 0;
assert response.body() != null;
for(int i = 0; i < response.body().size(); i++) {
Branches branches = response.body().get(i);
branchesList.add(branches.getName());
if(tinyDB.getString("repoBranch").equals(branches.getName())) {
selectedBranch = i;
}
}
AlertDialog.Builder pBuilder = new AlertDialog.Builder(ctx);
pBuilder.setTitle(R.string.pageTitleChooseBranch);
pBuilder.setSingleChoiceItems(branchesList.toArray(new String[0]), selectedBranch, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
tinyDB.putString("repoBranch", branchesList.get(i));
if(getFragmentRefreshListenerFiles() != null) {
getFragmentRefreshListenerFiles().onRefresh(branchesList.get(i));
}
dialogInterface.dismiss();
}
});
pBuilder.setNeutralButton(R.string.cancelButton, null);
pBuilder.create().show();
}
}
@Override
public void onFailure(@NonNull Call<List<Branches>> call, @NonNull Throwable t) {
Log.e("onFailure", t.toString());
}
});
}
public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
SectionsPagerAdapter(FragmentManager fm) {
@ -393,7 +480,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
return RepoInfoFragment.newInstance(repositoryOwner, repositoryName);
case 1: // Files
return FilesFragment.newInstance(repositoryOwner, repositoryName);
return FilesFragment.newInstance(repositoryOwner, repositoryName, tinyDB.getString("repoBranch"));
case 2: // Issues
fragment = new IssuesFragment();
@ -444,32 +531,28 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
UserRepositories repoInfo = response.body();
if(response.isSuccessful()) {
if(response.code() == 200) {
if(response.code() == 200) {
if(tinyDB.getBoolean("enableCounterBadges")) {
assert repoInfo != null;
if(tinyDB.getBoolean("enableCounterBadges")) {
assert repoInfo != null;
if(repoInfo.getOpen_issues_count() != null) {
if(repoInfo.getOpen_issues_count() != null) {
textViewBadgeIssue.setVisibility(View.VISIBLE);
textViewBadgeIssue.setText(repoInfo.getOpen_issues_count());
}
if(repoInfo.getOpen_pull_count() != null) {
textViewBadgePull.setVisibility(View.VISIBLE);
textViewBadgePull.setText(repoInfo.getOpen_pull_count());
}
if(repoInfo.getRelease_count() != null) {
textViewBadgeRelease.setVisibility(View.VISIBLE);
textViewBadgeRelease.setText(repoInfo.getRelease_count());
}
textViewBadgeIssue.setVisibility(View.VISIBLE);
textViewBadgeIssue.setText(repoInfo.getOpen_issues_count());
}
if(repoInfo.getOpen_pull_count() != null) {
textViewBadgePull.setVisibility(View.VISIBLE);
textViewBadgePull.setText(repoInfo.getOpen_pull_count());
}
if(repoInfo.getRelease_count() != null) {
textViewBadgeRelease.setVisibility(View.VISIBLE);
textViewBadgeRelease.setText(repoInfo.getRelease_count());
}
}
}
@ -567,4 +650,11 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
public interface FragmentRefreshListenerMilestone { void onRefresh(String text); }
// Files interface
public FragmentRefreshListenerFiles getFragmentRefreshListenerFiles() { return fragmentRefreshListenerFiles; }
public void setFragmentRefreshListenerFiles(FragmentRefreshListenerFiles fragmentRefreshListenerFiles) { this.fragmentRefreshListenerFiles = fragmentRefreshListenerFiles; }
public interface FragmentRefreshListenerFiles { void onRefresh(String text); }
}

View File

@ -0,0 +1,296 @@
package org.mian.gitnex.activities;
import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.RepoForksAdapter;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.models.UserRepositories;
import java.util.ArrayList;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
* Author M M Arif
*/
public class RepoForksActivity extends BaseActivity {
final Context ctx = this;
private Context appCtx;
private View.OnClickListener onClickListener;
private TextView noData;
private ProgressBar progressBar;
private String TAG = "RepositoryForks";
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
private int pageSize = 1;
private RecyclerView recyclerView;
private List<UserRepositories> forksList;
private RepoForksAdapter adapter;
private ProgressBar progressLoadMore;
@Override
protected int getLayoutResourceId() {
return R.layout.activity_forks;
}
@SuppressLint("DefaultLocale")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
TinyDB tinyDb = new TinyDB(appCtx);
final String instanceUrl = tinyDb.getString("instanceUrl");
final String loginUid = tinyDb.getString("loginUid");
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
String repoFullNameForForks = getIntent().getStringExtra("repoFullNameForForks");
assert repoFullNameForForks != null;
String[] parts = repoFullNameForForks.split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
TextView toolbar_title = findViewById(R.id.toolbar_title);
toolbar_title.setMovementMethod(new ScrollingMovementMethod());
toolbar_title.setText(String.format("%s : %s", ctx.getResources().getString(R.string.infoTabRepoForksCount), repoName));
ImageView closeActivity = findViewById(R.id.close);
noData = findViewById(R.id.noData);
progressLoadMore = findViewById(R.id.progressLoadMore);
progressBar = findViewById(R.id.progress_bar);
SwipeRefreshLayout swipeRefresh = findViewById(R.id.pullToRefresh);
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
// if gitea is 1.12 or higher use the new limit (resultLimitNewGiteaInstances)
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12")) {
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
}
recyclerView = findViewById(R.id.recyclerView);
forksList = new ArrayList<>();
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
DividerItemDecoration.VERTICAL);
recyclerView.addItemDecoration(dividerItemDecoration);
swipeRefresh.setOnRefreshListener(() -> new Handler().postDelayed(() -> {
swipeRefresh.setRefreshing(false);
loadInitial(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, pageSize, resultLimit);
adapter.notifyDataChanged();
}, 200));
adapter = new RepoForksAdapter(ctx, forksList);
adapter.setLoadMoreListener(() -> recyclerView.post(() -> {
if(forksList.size() == resultLimit || pageSize == resultLimit) {
int page = (forksList.size() + resultLimit) / resultLimit;
loadMore(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, page, resultLimit);
}
}));
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
recyclerView.setAdapter(adapter);
loadInitial(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, pageSize, resultLimit);
}
private void loadInitial(String instanceUrl, String instanceToken, String repoOwner, String repoName, int pageSize, int resultLimit) {
Call<List<UserRepositories>> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.getRepositoryForks(instanceToken, repoOwner, repoName, pageSize, resultLimit);
call.enqueue(new Callback<List<UserRepositories>>() {
@Override
public void onResponse(@NonNull Call<List<UserRepositories>> call, @NonNull Response<List<UserRepositories>> response) {
if(response.isSuccessful()) {
assert response.body() != null;
if(response.body().size() > 0) {
forksList.clear();
forksList.addAll(response.body());
adapter.notifyDataChanged();
noData.setVisibility(View.GONE);
}
else {
forksList.clear();
adapter.notifyDataChanged();
noData.setVisibility(View.VISIBLE);
}
progressBar.setVisibility(View.GONE);
}
else {
Log.e(TAG, String.valueOf(response.code()));
}
}
@Override
public void onFailure(@NonNull Call<List<UserRepositories>> call, @NonNull Throwable t) {
Log.e(TAG, t.toString());
}
});
}
private void loadMore(String instanceUrl, String instanceToken, String repoOwner, String repoName, int page, int resultLimit) {
progressLoadMore.setVisibility(View.VISIBLE);
Call<List<UserRepositories>> call = RetrofitClient
.getInstance(instanceUrl, ctx)
.getApiInterface()
.getRepositoryForks(instanceToken, repoOwner, repoName, page, resultLimit);
call.enqueue(new Callback<List<UserRepositories>>() {
@Override
public void onResponse(@NonNull Call<List<UserRepositories>> call, @NonNull Response<List<UserRepositories>> response) {
if(response.isSuccessful()) {
//remove loading view
forksList.remove(forksList.size() - 1);
List<UserRepositories> result = response.body();
assert result != null;
if(result.size() > 0) {
pageSize = result.size();
forksList.addAll(result);
}
else {
adapter.setMoreDataAvailable(false);
}
adapter.notifyDataChanged();
progressLoadMore.setVisibility(View.GONE);
}
else {
Log.e(TAG, String.valueOf(response.code()));
}
}
@Override
public void onFailure(@NonNull Call<List<UserRepositories>> call, @NonNull Throwable t) {
Log.e(TAG, t.toString());
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.search_menu, menu);
MenuItem searchItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchItem.getActionView();
searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
filter(newText);
return true;
}
});
return super.onCreateOptionsMenu(menu);
}
private void filter(String text) {
List<UserRepositories> arr = new ArrayList<>();
for(UserRepositories d : forksList) {
if(d.getName().toLowerCase().contains(text) || d.getDescription().toLowerCase().contains(text)) {
arr.add(d);
}
}
adapter.updateList(arr);
}
private void initCloseListener() {
onClickListener = view -> {
getIntent().removeExtra("repoFullNameForForks");
finish();
};
}
}

View File

@ -2,19 +2,19 @@ package org.mian.gitnex.activities;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.RepoStargazersAdapter;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.viewmodels.RepoStargazersViewModel;
import java.util.List;
@ -93,12 +93,8 @@ public class RepoStargazersActivity extends BaseActivity {
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
onClickListener = view -> finish();
}
}

View File

@ -2,19 +2,19 @@ package org.mian.gitnex.activities;
import android.content.Context;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.RepoWatchersAdapter;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.viewmodels.RepoWatchersViewModel;
import java.util.List;
@ -93,12 +93,8 @@ public class RepoWatchersActivity extends BaseActivity {
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
onClickListener = view -> finish();
}
}

View File

@ -9,8 +9,9 @@ import android.widget.Switch;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.helpers.Version;
/**
* Author M M Arif
@ -27,7 +28,8 @@ public class SettingsAppearanceActivity extends BaseActivity {
private static String[] codeBlockList = {"Green - Black", "White - Black", "Grey - Black", "White - Grey", "Dark - White"};
private static int codeBlockSelectedChoice = 0;
private static String[] homeScreenList = {"My Repositories", "Starred Repositories", "Organizations", "Repositories", "Profile"};
private static String[] homeScreenList = {"My Repositories", "Starred Repositories", "Organizations", "Repositories", "Profile", "Explore", "Drafts"};
private static String[] homeScreenListNew = {"My Repositories", "Starred Repositories", "Organizations", "Repositories", "Profile", "Explore", "Drafts", "Notifications"};
private static int homeScreenSelectedChoice = 0;
private static String[] customFontList = {"Roboto", "Manrope", "Source Code Pro"};
@ -69,6 +71,11 @@ public class SettingsAppearanceActivity extends BaseActivity {
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.3")) {
homeScreenList = homeScreenListNew;
}
if(!tinyDb.getString("timeStr").isEmpty()) {
tvDateTimeSelected.setText(tinyDb.getString("timeStr"));
}
@ -121,11 +128,11 @@ public class SettingsAppearanceActivity extends BaseActivity {
if (isChecked) {
tinyDb.putBoolean("enableCounterBadges", true);
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
}
else {
tinyDb.putBoolean("enableCounterBadges", false);
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
}
});
@ -154,7 +161,7 @@ public class SettingsAppearanceActivity extends BaseActivity {
this.recreate();
this.overridePendingTransition(0, 0);
dialogInterfaceTheme.dismiss();
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
@ -187,7 +194,7 @@ public class SettingsAppearanceActivity extends BaseActivity {
this.recreate();
this.overridePendingTransition(0, 0);
dialogInterfaceCustomFont.dismiss();
Toasty.info(appCtx, appCtx.getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, appCtx.getResources().getString(R.string.settingsSave));
});
@ -217,7 +224,7 @@ public class SettingsAppearanceActivity extends BaseActivity {
tinyDb.putInt("homeScreenId", i);
dialogInterfaceHomeScreen.dismiss();
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
@ -248,7 +255,7 @@ public class SettingsAppearanceActivity extends BaseActivity {
switch(codeBlockList[i]) {
case "White - Black":
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.white));
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorWhite));
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
break;
case "Grey - Black":
@ -256,12 +263,12 @@ public class SettingsAppearanceActivity extends BaseActivity {
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
break;
case "White - Grey":
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.white));
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorWhite));
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.colorAccent));
break;
case "Dark - White":
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorPrimary));
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.white));
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.colorWhite));
break;
default:
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorLightGreen));
@ -270,7 +277,7 @@ public class SettingsAppearanceActivity extends BaseActivity {
}
dialogInterfaceCodeBlock.dismiss();
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
@ -307,7 +314,7 @@ public class SettingsAppearanceActivity extends BaseActivity {
}
dialogInterfaceTime.dismiss();
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
@ -320,9 +327,7 @@ public class SettingsAppearanceActivity extends BaseActivity {
}
private void initCloseListener() {
onClickListener = view -> {
finish();
};
onClickListener = view -> finish();
}
}

View File

@ -0,0 +1,67 @@
package org.mian.gitnex.activities;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Switch;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.TinyDB;
/**
* Author M M Arif
*/
public class SettingsDraftsActivity extends BaseActivity {
private Context appCtx;
private View.OnClickListener onClickListener;
@Override
protected int getLayoutResourceId() {
return R.layout.activity_settings_drafts;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
TinyDB tinyDb = new TinyDB(appCtx);
ImageView closeActivity = findViewById(R.id.close);
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
Switch commentsDeletionSwitch = findViewById(R.id.commentsDeletionSwitch);
if(tinyDb.getBoolean("draftsCommentsDeletionEnabled")) {
commentsDeletionSwitch.setChecked(true);
}
else {
commentsDeletionSwitch.setChecked(false);
}
// delete comments on submit switcher
commentsDeletionSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
if(isChecked) {
tinyDb.putBoolean("draftsCommentsDeletionEnabled", true);
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
}
else {
tinyDb.putBoolean("draftsCommentsDeletionEnabled", false);
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
}
});
}
private void initCloseListener() { onClickListener = view -> finish(); }
}

View File

@ -9,8 +9,8 @@ import android.widget.Switch;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.util.TinyDB;
/**
* Author M M Arif
@ -85,7 +85,7 @@ public class SettingsFileViewerActivity extends BaseActivity {
tinyDb.putInt("fileviewerSourceCodeThemeId", i);
dialogInterfaceTheme.dismiss();
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
@ -100,12 +100,12 @@ public class SettingsFileViewerActivity extends BaseActivity {
if(isChecked) {
tinyDb.putBoolean("enablePdfMode", true);
tinyDb.putString("enablePdfModeInit", "yes");
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
}
else {
tinyDb.putBoolean("enablePdfMode", false);
tinyDb.putString("enablePdfModeInit", "yes");
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
}
});

View File

@ -6,8 +6,8 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.Switch;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.util.TinyDB;
/**
* Author M M Arif
@ -51,11 +51,11 @@ public class SettingsReportsActivity extends BaseActivity {
if(isChecked) {
tinyDb.putBoolean("crashReportingEnabled", true);
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
}
else {
tinyDb.putBoolean("crashReportingEnabled", false);
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
}
});
@ -63,9 +63,7 @@ public class SettingsReportsActivity extends BaseActivity {
}
private void initCloseListener() {
onClickListener = view -> {
finish();
};
onClickListener = view -> finish();
}
}

View File

@ -7,15 +7,18 @@ import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import org.apache.commons.io.FileUtils;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.FilesData;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.helpers.Version;
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.notifications.NotificationsMaster;
import java.io.File;
import java.io.IOException;
import java.util.HashSet;
@ -27,6 +30,8 @@ import java.util.HashSet;
public class SettingsSecurityActivity extends BaseActivity {
private Context appCtx;
private Context ctx = this;
private View.OnClickListener onClickListener;
private static String[] cacheSizeDataList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"};
@ -35,6 +40,10 @@ public class SettingsSecurityActivity extends BaseActivity {
private static String[] cacheSizeImagesList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"};
private static int cacheSizeImagesSelectedChoice = 0;
private static int MINIMUM_POLLING_DELAY = 1;
private static int DEFAULT_POLLING_DELAY = 20;
private static int MAXIMUM_POLLING_DELAY = 720;
@Override
protected int getLayoutResourceId() {
@ -48,6 +57,7 @@ public class SettingsSecurityActivity extends BaseActivity {
appCtx = getApplicationContext();
TinyDB tinyDb = new TinyDB(appCtx);
String currentVersion = tinyDb.getString("giteaVersion");
ImageView closeActivity = findViewById(R.id.close);
@ -57,8 +67,10 @@ public class SettingsSecurityActivity extends BaseActivity {
TextView cacheSizeDataSelected = findViewById(R.id.cacheSizeDataSelected); // setter for data cache size
TextView cacheSizeImagesSelected = findViewById(R.id.cacheSizeImagesSelected); // setter for images cache size
TextView clearCacheSelected = findViewById(R.id.clearCacheSelected); // setter for clear cache
TextView pollingDelaySelected = findViewById(R.id.pollingDelaySelected);
LinearLayout certsFrame = findViewById(R.id.certsFrame);
LinearLayout pollingDelayFrame = findViewById(R.id.pollingDelayFrame);
LinearLayout cacheSizeDataFrame = findViewById(R.id.cacheSizeDataSelectionFrame);
LinearLayout cacheSizeImagesFrame = findViewById(R.id.cacheSizeImagesSelectionFrame);
LinearLayout clearCacheFrame = findViewById(R.id.clearCacheSelectionFrame);
@ -79,6 +91,12 @@ public class SettingsSecurityActivity extends BaseActivity {
cacheSizeImagesSelectedChoice = tinyDb.getInt("cacheSizeImagesId");
}
if(new Version(currentVersion).less("1.12.3")) {
pollingDelayFrame.setVisibility(View.GONE);
}
pollingDelaySelected.setText(String.format(getString(R.string.pollingDelaySelectedText), tinyDb.getInt("pollingDelayMinutes", DEFAULT_POLLING_DELAY)));
// clear cache setter
File cacheDir = appCtx.getCacheDir();
long size__ = FilesData.getFileSizeRecursively(new HashSet<>(), cacheDir);
@ -137,7 +155,7 @@ public class SettingsSecurityActivity extends BaseActivity {
tinyDb.putInt("cacheSizeImagesId", i);
dialogInterfaceTheme.dismiss();
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
@ -167,7 +185,7 @@ public class SettingsSecurityActivity extends BaseActivity {
tinyDb.putInt("cacheSizeId", i);
dialogInterfaceTheme.dismiss();
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
@ -190,7 +208,6 @@ public class SettingsSecurityActivity extends BaseActivity {
tinyDb.putBoolean("loggedInMode", false);
tinyDb.remove("basicAuthPassword");
tinyDb.putBoolean("basicAuthFlag", false);
//tinyDb.clear();
Intent loginActivityIntent = new Intent().setClass(appCtx, LoginActivity.class);
loginActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@ -203,12 +220,42 @@ public class SettingsSecurityActivity extends BaseActivity {
});
// polling delay
pollingDelayFrame.setOnClickListener(v -> {
NumberPicker numberPicker = new NumberPicker(ctx);
numberPicker.setMinValue(MINIMUM_POLLING_DELAY);
numberPicker.setMaxValue(MAXIMUM_POLLING_DELAY);
numberPicker.setValue(tinyDb.getInt("pollingDelayMinutes", DEFAULT_POLLING_DELAY));
numberPicker.setWrapSelectorWheel(true);
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(getString(R.string.pollingDelayDialogHeaderText));
builder.setMessage(getString(R.string.pollingDelayDialogDescriptionText));
builder.setCancelable(true);
builder.setPositiveButton(getString(R.string.okButton), (dialog, which) -> {
tinyDb.putInt("pollingDelayMinutes", numberPicker.getValue());
NotificationsMaster.fireWorker(ctx);
NotificationsMaster.hireWorker(ctx);
pollingDelaySelected.setText(String.format(getString(R.string.pollingDelaySelectedText), numberPicker.getValue()));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
builder.setNeutralButton(R.string.cancelButton, null);
builder.setView(numberPicker);
builder.create().show();
});
}
private void initCloseListener() {
onClickListener = view -> {
finish();
};
}
onClickListener = view -> finish();
}
}

View File

@ -10,8 +10,8 @@ import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.util.TinyDB;
/**
* Author M M Arif
@ -143,11 +143,11 @@ public class SettingsTranslationActivity extends BaseActivity {
this.recreate();
this.overridePendingTransition(0, 0);
dialogInterface.dismiss();
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
});
lBuilder.setNegativeButton(getString(R.string.cancelButton), (dialog, which) -> dialog.dismiss());
lBuilder.setNeutralButton(getString(R.string.cancelButton), null);
AlertDialog lDialog = lBuilder.create();
lDialog.show();
@ -157,9 +157,7 @@ public class SettingsTranslationActivity extends BaseActivity {
}
private void initCloseListener() {
onClickListener = view -> {
finish();
};
onClickListener = view -> finish();
}
}

View File

@ -1,70 +0,0 @@
package org.mian.gitnex.activities;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Context;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import org.mian.gitnex.R;
import org.mian.gitnex.adapters.SponsorsAdapter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
* Author M M Arif
*/
public class SponsorsActivity extends BaseActivity {
private View.OnClickListener onClickListener;
private Context appCtx;
@Override
protected int getLayoutResourceId(){
return R.layout.activity_sponsors;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
appCtx = getApplicationContext();
ImageView closeActivity = findViewById(R.id.close);
initCloseListener();
closeActivity.setOnClickListener(onClickListener);
Resources res = getResources();
CharSequence[] sponsorsInfo = res.getTextArray(R.array.sponsorsInfo);
List<CharSequence> sponsorsList = new ArrayList<>(Arrays.asList(sponsorsInfo));
RecyclerView mRecyclerView = findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new LinearLayoutManager(appCtx));
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(mRecyclerView.getContext(),
DividerItemDecoration.VERTICAL);
mRecyclerView.addItemDecoration(dividerItemDecoration);
SponsorsAdapter adapter = new SponsorsAdapter(sponsorsList);
mRecyclerView.setAdapter(adapter);
}
private void initCloseListener() {
onClickListener = new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
};
}
}

View File

@ -86,7 +86,7 @@ public class AdminGetUsersAdapter extends RecyclerView.Adapter<AdminGetUsersAdap
holder.userRole.setVisibility(View.VISIBLE);
TextDrawable drawable = TextDrawable.builder()
.beginConfig()
.textColor(mCtx.getResources().getColor(R.color.white))
.textColor(mCtx.getResources().getColor(R.color.colorWhite))
.fontSize(44)
.width(180)
.height(60)

View File

@ -7,14 +7,14 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.CommitsActivity;
import org.mian.gitnex.models.Branches;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
import java.util.Objects;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.CommitsActivity;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.Branches;
import java.util.List;
import java.util.Objects;
/**
* Author M M Arif

View File

@ -14,8 +14,8 @@ import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.ClickListener;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.Commits;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
import java.util.Locale;

View File

@ -0,0 +1,158 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.text.Html;
import android.text.Spanned;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.ReplyToIssueActivity;
import org.mian.gitnex.database.api.DraftsApi;
import org.mian.gitnex.database.models.DraftWithRepository;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import java.util.List;
/**
* Author M M Arif
*/
public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsViewHolder> {
private List<DraftWithRepository> draftsList;
private Context mCtx;
class DraftsViewHolder extends RecyclerView.ViewHolder {
private TextView draftText;
private TextView repoInfo;
private TextView repoId;
private TextView draftId;
private TextView issueNumber;
private TextView issueType;
private TextView repoOwner;
private TextView repoName;
private TextView commentId;
private ImageView editCommentStatus;
private DraftsViewHolder(View itemView) {
super(itemView);
draftText = itemView.findViewById(R.id.draftText);
repoInfo = itemView.findViewById(R.id.repoInfo);
repoId = itemView.findViewById(R.id.repoId);
draftId = itemView.findViewById(R.id.draftId);
issueNumber = itemView.findViewById(R.id.issueNumber);
issueType = itemView.findViewById(R.id.issueType);
repoOwner = itemView.findViewById(R.id.repoOwner);
repoName = itemView.findViewById(R.id.repoName);
commentId = itemView.findViewById(R.id.commentId);
ImageView deleteDraft = itemView.findViewById(R.id.deleteDraft);
editCommentStatus = itemView.findViewById(R.id.editCommentStatus);
deleteDraft.setOnClickListener(itemDelete -> {
int getDraftId = Integer.parseInt(draftId.getText().toString());
deleteDraft(getAdapterPosition());
DraftsApi draftsApi = new DraftsApi(mCtx);
draftsApi.deleteSingleDraft(getDraftId);
});
itemView.setOnClickListener(itemEdit -> {
Intent intent = new Intent(mCtx, ReplyToIssueActivity.class);
intent.putExtra("commentBody", draftText.getText().toString());
intent.putExtra("issueNumber", issueNumber.getText().toString());
intent.putExtra("repositoryId", repoId.getText().toString());
intent.putExtra("draftTitle", repoInfo.getText().toString());
intent.putExtra("commentId", commentId.getText().toString());
intent.putExtra("draftId", draftId.getText().toString());
if(!commentId.getText().toString().equalsIgnoreCase("")) {
intent.putExtra("commentAction", "edit");
}
TinyDB tinyDb = new TinyDB(mCtx);
tinyDb.putString("issueNumber", issueNumber.getText().toString());
tinyDb.putLong("repositoryId", Long.parseLong(repoId.getText().toString()));
//tinyDb.putString("issueType", issueType.getText().toString());
mCtx.startActivity(intent);
});
}
}
public DraftsAdapter(Context mCtx, List<DraftWithRepository> draftsListMain) {
this.mCtx = mCtx;
this.draftsList = draftsListMain;
}
private void deleteDraft(int position) {
draftsList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, draftsList.size());
Toasty.success(mCtx, mCtx.getResources().getString(R.string.draftsSingleDeleteSuccess));
}
@NonNull
@Override
public DraftsAdapter.DraftsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_drafts, parent, false);
return new DraftsViewHolder(v);
}
@SuppressLint("DefaultLocale")
@Override
public void onBindViewHolder(@NonNull DraftsAdapter.DraftsViewHolder holder, int position) {
DraftWithRepository currentItem = draftsList.get(position);
holder.repoId.setText(String.valueOf(currentItem.getRepositoryId()));
holder.draftId.setText(String.valueOf(currentItem.getDraftId()));
holder.issueNumber.setText(String.valueOf(currentItem.getIssueId()));
holder.issueType.setText(currentItem.getDraftType());
holder.repoOwner.setText(currentItem.getRepositoryOwner());
holder.repoName.setText(currentItem.getRepositoryName());
holder.draftText.setText(currentItem.getDraftText());
holder.commentId.setText(currentItem.getCommentId());
String issueNumber = "<font color='" + mCtx.getResources().getColor(R.color.lightGray) + "'>" + mCtx.getResources().getString(R.string.hash) + currentItem.getIssueId() + "</font>";
Spanned headTitle = Html.fromHtml(issueNumber + " " + currentItem.getRepositoryOwner() + " / " + currentItem.getRepositoryName());
holder.repoInfo.setText(headTitle);
if(!currentItem.getCommentId().equalsIgnoreCase("new")) {
holder.editCommentStatus.setVisibility(View.VISIBLE);
}
else {
holder.editCommentStatus.setVisibility(View.GONE);
}
}
@Override
public int getItemCount() {
return draftsList.size();
}
public void updateList(List<DraftWithRepository> list) {
draftsList = list;
notifyDataSetChanged();
}
}

View File

@ -1,6 +1,8 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
@ -19,16 +21,20 @@ import com.google.android.material.bottomsheet.BottomSheetDialog;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.OpenRepoInBrowserActivity;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.activities.RepoForksActivity;
import org.mian.gitnex.activities.RepoStargazersActivity;
import org.mian.gitnex.activities.RepoWatchersActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.UserRepositories;
import org.mian.gitnex.models.WatchInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
@ -38,7 +44,6 @@ import retrofit2.Callback;
public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepositoriesAdapter.ReposSearchViewHolder> {
private List<UserRepositories> searchedReposList;
private Context mCtx;
@ -61,6 +66,8 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
private TextView repoOpenIssuesCount;
private TextView repoType;
private LinearLayout archiveRepo;
private TextView repoBranch;
private TextView htmlUrl;
private ReposSearchViewHolder(View itemView) {
@ -78,6 +85,8 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
repoType = itemView.findViewById(R.id.repoType);
archiveRepo = itemView.findViewById(R.id.archiveRepoFrame);
repoBranch = itemView.findViewById(R.id.repoBranch);
htmlUrl = itemView.findViewById(R.id.htmlUrl);
itemView.setOnClickListener(v -> {
@ -91,13 +100,35 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
tinyDb.putString("repoFullName", repoFullName.getText().toString());
tinyDb.putBoolean("resumeIssues", true);
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
tinyDb.putString("repoBranch", repoBranch.getText().toString());
String[] parts = fullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
if(count == 0) {
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", id);
}
else {
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", data.getRepositoryId());
}
//store if user is watching this repo
{
final String instanceUrl = tinyDb.getString("instanceUrl");
String[] parts = repoFullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
WatchInfo watch = new WatchInfo();
@ -122,7 +153,7 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
if(response.code() != 404) {
Toasty.info(context, context.getString(R.string.genericApiStatusError));
Toasty.error(context, context.getString(R.string.genericApiStatusError));
}
@ -134,10 +165,11 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
tinyDb.putBoolean("repoWatch", false);
Toasty.info(context, context.getString(R.string.genericApiStatusError));
Toasty.error(context, context.getString(R.string.genericApiStatusError));
}
});
}
context.startActivity(intent);
@ -153,6 +185,8 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
TextView repoForksList = view.findViewById(R.id.repoForksList);
TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl);
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
bottomSheetHeader.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1]));
@ -160,6 +194,17 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
dialog.setContentView(view);
dialog.show();
repoCopyUrl.setOnClickListener(openInBrowser -> {
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString());
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg));
dialog.dismiss();
});
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
@ -187,6 +232,15 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
});
repoForksList.setOnClickListener(forks -> {
Intent intentW = new Intent(context, RepoForksActivity.class);
intentW.putExtra("repoFullNameForForks", fullName.getText());
context.startActivity(intentW);
dialog.dismiss();
});
});
}
@ -204,10 +258,10 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
@Override
public void onBindViewHolder(@NonNull final ExploreRepositoriesAdapter.ReposSearchViewHolder holder, int position) {
final UserRepositories currentItem = searchedReposList.get(position);
UserRepositories currentItem = searchedReposList.get(position);
holder.repoDescription.setVisibility(View.GONE);
holder.repoBranch.setText(currentItem.getDefault_branch());
holder.htmlUrl.setText(currentItem.getHtml_url());
ColorGenerator generator = ColorGenerator.MATERIAL;
int color = generator.getColor(currentItem.getName());
@ -234,11 +288,11 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
}
holder.fullName.setText(currentItem.getFullname());
if(currentItem.getPrivateFlag()) {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock);
holder.repoType.setText(R.string.strPrivate);
}
else {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
holder.repoPrivatePublic.setVisibility(View.GONE);
holder.repoType.setText(R.string.strPublic);
}
holder.repoStars.setText(currentItem.getStars_count());

View File

@ -11,9 +11,9 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.Files;
import org.mian.gitnex.util.AppUtil;
import java.util.ArrayList;
import java.util.List;
@ -51,23 +51,20 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
//ImageView filesDropdownMenu = itemView.findViewById(R.id.filesDropdownMenu);
fileName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fileName.setOnClickListener(v -> {
Context context = v.getContext();
if(fileType.getText().toString().equals("file")) {
filesListener.onClickFile(fileName.getText().toString());
}
else if(fileType.getText().toString().equals("dir")) {
filesListener.onClickDir(fileName.getText().toString());
}
else {
Toasty.info(context, context.getString(R.string.filesGenericError));
}
Context context = v.getContext();
if(fileType.getText().toString().equals("file")) {
filesListener.onClickFile(fileName.getText().toString());
}
else if(fileType.getText().toString().equals("dir")) {
filesListener.onClickDir(fileName.getText().toString());
}
else {
Toasty.warning(context, context.getString(R.string.filesGenericError));
}
});
@ -160,16 +157,16 @@ public class FilesAdapter extends RecyclerView.Adapter<FilesAdapter.FilesViewHol
holder.fileName.setText(currentItem.getName());
if(currentItem.getType().equals("file")) {
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_file_new));
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_file));
holder.fileInfo.setVisibility(View.VISIBLE);
holder.fileInfo.setText(AppUtil.formatFileSizeInDetail(currentItem.getSize()));
}
else if(currentItem.getType().equals("dir")) {
holder.fileInfo.setVisibility(View.GONE);
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_folder_24));
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_directory));
}
else {
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_question_mark_24));
holder.fileTypeImage.setImageDrawable(mCtx.getResources().getDrawable(R.drawable.ic_question));
}
}

View File

@ -26,10 +26,10 @@ import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.ClickListener;
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.UserMentions;
import org.mian.gitnex.models.IssueComments;
import org.mian.gitnex.util.TinyDB;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -242,7 +242,7 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
if(response.code() == 204) {
updateAdapter(position);
Toasty.info(ctx, ctx.getResources().getString(R.string.deleteCommentSuccess));
Toasty.success(ctx, ctx.getResources().getString(R.string.deleteCommentSuccess));
}
else if(response.code() == 401) {
@ -255,17 +255,17 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
}
else if(response.code() == 403) {
Toasty.info(ctx, ctx.getString(R.string.authorizeError));
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
Toasty.info(ctx, ctx.getString(R.string.apiNotFound));
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
}
else {
Toasty.info(ctx, ctx.getString(R.string.genericError));
Toasty.error(ctx, ctx.getString(R.string.genericError));
}

View File

@ -18,8 +18,8 @@ import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.helpers.ClickListener;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.Issues;
import org.mian.gitnex.util.TinyDB;
import org.ocpsoft.prettytime.PrettyTime;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@ -125,7 +125,7 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
TinyDB tinyDb = new TinyDB(context);
tinyDb.putString("issueNumber", issueNumber.getText().toString());
tinyDb.putString("issueType", "issue");
tinyDb.putString("issueType", "Issue");
context.startActivity(intent);
});
@ -138,7 +138,7 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
TinyDB tinyDb = new TinyDB(context);
tinyDb.putString("issueNumber", issueNumber.getText().toString());
tinyDb.putString("issueType", "issue");
tinyDb.putString("issueType", "Issue");
context.startActivity(intent);
});

View File

@ -21,8 +21,8 @@ import org.mian.gitnex.actions.MilestoneActions;
import org.mian.gitnex.helpers.ClickListener;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.Milestones;
import org.mian.gitnex.util.TinyDB;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

View File

@ -11,14 +11,14 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.MultiSelectDialog;
import org.mian.gitnex.models.MultiSelectModel;
import java.util.ArrayList;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.MultiSelectDialog;
import org.mian.gitnex.models.MultiSelectModel;
import java.util.List;
/**
* Author com.github.abumoallim, modified by M M Arif
@ -26,11 +26,11 @@ import androidx.recyclerview.widget.RecyclerView;
public class MutliSelectAdapter extends RecyclerView.Adapter<MutliSelectAdapter.MultiSelectDialogViewHolder> {
private ArrayList<MultiSelectModel> mDataSet;
private List<MultiSelectModel> mDataSet;
private String mSearchQuery = "";
private Context mContext;
public MutliSelectAdapter(ArrayList<MultiSelectModel> dataSet, Context context) {
public MutliSelectAdapter(List<MultiSelectModel> dataSet, Context context) {
this.mDataSet = dataSet;
this.mContext = context;
}
@ -163,7 +163,7 @@ public class MutliSelectAdapter extends RecyclerView.Adapter<MutliSelectAdapter.
return mDataSet.size();
}
public void setData(ArrayList<MultiSelectModel> data, String query, MutliSelectAdapter mutliSelectAdapter) {
public void setData(List<MultiSelectModel> data, String query, MutliSelectAdapter mutliSelectAdapter) {
this.mDataSet = data;
this.mSearchQuery = query;
@ -187,4 +187,4 @@ public class MutliSelectAdapter extends RecyclerView.Adapter<MutliSelectAdapter.
}
}
}
}

View File

@ -1,6 +1,8 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
@ -13,25 +15,29 @@ import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.OpenRepoInBrowserActivity;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.activities.RepoForksActivity;
import org.mian.gitnex.activities.RepoStargazersActivity;
import org.mian.gitnex.activities.RepoWatchersActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.UserRepositories;
import org.mian.gitnex.models.WatchInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
@ -41,267 +47,322 @@ import retrofit2.Callback;
public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter.MyReposViewHolder> implements Filterable {
private List<UserRepositories> reposList;
private Context mCtx;
private List<UserRepositories> reposListFull;
private List<UserRepositories> reposList;
private Context mCtx;
private List<UserRepositories> reposListFull;
static class MyReposViewHolder extends RecyclerView.ViewHolder {
static class MyReposViewHolder extends RecyclerView.ViewHolder {
private ImageView imageAvatar;
private TextView repoName;
private TextView repoDescription;
private TextView repoFullName;
private ImageView repoPrivatePublic;
private TextView repoStars;
private TextView repoForks;
private TextView repoOpenIssuesCount;
private TextView repoType;
private CheckBox isRepoAdmin;
private LinearLayout archiveRepo;
private ImageView imageAvatar;
private TextView repoName;
private TextView repoDescription;
private TextView repoFullName;
private ImageView repoPrivatePublic;
private TextView repoStars;
private TextView repoForks;
private TextView repoOpenIssuesCount;
private TextView repoType;
private CheckBox isRepoAdmin;
private LinearLayout archiveRepo;
private TextView repoBranch;
private TextView htmlUrl;
private MyReposViewHolder(View itemView) {
super(itemView);
repoName = itemView.findViewById(R.id.repoName);
repoDescription = itemView.findViewById(R.id.repoDescription);
imageAvatar = itemView.findViewById(R.id.imageAvatar);
repoFullName = itemView.findViewById(R.id.repoFullName);
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
repoStars = itemView.findViewById(R.id.repoStars);
repoForks = itemView.findViewById(R.id.repoForks);
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
repoType = itemView.findViewById(R.id.repoType);
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
archiveRepo = itemView.findViewById(R.id.archiveRepoFrame);
private MyReposViewHolder(View itemView) {
itemView.setOnClickListener(v -> {
super(itemView);
repoName = itemView.findViewById(R.id.repoName);
repoDescription = itemView.findViewById(R.id.repoDescription);
imageAvatar = itemView.findViewById(R.id.imageAvatar);
repoFullName = itemView.findViewById(R.id.repoFullName);
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
repoStars = itemView.findViewById(R.id.repoStars);
repoForks = itemView.findViewById(R.id.repoForks);
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
repoType = itemView.findViewById(R.id.repoType);
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
archiveRepo = itemView.findViewById(R.id.archiveRepoFrame);
repoBranch = itemView.findViewById(R.id.repoBranch);
htmlUrl = itemView.findViewById(R.id.htmlUrl);
Context context = v.getContext();
itemView.setOnClickListener(v -> {
Intent intent = new Intent(context, RepoDetailActivity.class);
intent.putExtra("repoFullName", repoFullName.getText().toString());
Context context = v.getContext();
TinyDB tinyDb = new TinyDB(context);
tinyDb.putString("repoFullName", repoFullName.getText().toString());
tinyDb.putString("repoType", repoType.getText().toString());
//tinyDb.putBoolean("resumeIssues", true);
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
Intent intent = new Intent(context, RepoDetailActivity.class);
intent.putExtra("repoFullName", repoFullName.getText().toString());
//store if user is watching this repo
{
final String instanceUrl = tinyDb.getString("instanceUrl");
String[] parts = repoFullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
TinyDB tinyDb = new TinyDB(context);
tinyDb.putString("repoFullName", repoFullName.getText().toString());
tinyDb.putString("repoType", repoType.getText().toString());
//tinyDb.putBoolean("resumeIssues", true);
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
tinyDb.putString("repoBranch", repoBranch.getText().toString());
WatchInfo watch = new WatchInfo();
String[] parts = repoFullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
Call<WatchInfo> call;
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
call.enqueue(new Callback<WatchInfo>() {
if(count == 0) {
@Override
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", id);
if(response.isSuccessful()) {
}
else {
assert response.body() != null;
tinyDb.putBoolean("repoWatch", response.body().getSubscribed());
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", data.getRepositoryId());
} else {
}
tinyDb.putBoolean("repoWatch", false);
//store if user is watching this repo
{
if(response.code() != 404) {
final String instanceUrl = tinyDb.getString("instanceUrl");
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
Toasty.info(context, context.getString(R.string.genericApiStatusError));
WatchInfo watch = new WatchInfo();
}
Call<WatchInfo> call;
}
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
}
call.enqueue(new Callback<WatchInfo>() {
@Override
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
@Override
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
tinyDb.putBoolean("repoWatch", false);
Toasty.info(context, context.getString(R.string.genericApiStatusError));
if(response.isSuccessful()) {
}
});
}
assert response.body() != null;
tinyDb.putBoolean("repoWatch", response.body().getSubscribed());
context.startActivity(intent);
}
else {
});
tinyDb.putBoolean("repoWatch", false);
reposDropdownMenu.setOnClickListener(v -> {
if(response.code() != 404) {
final Context context = v.getContext();
Toasty.error(context, context.getString(R.string.genericApiStatusError));
@SuppressLint("InflateParams")
View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null);
}
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
}
bottomSheetHeader.setText(String.format("%s / %s", repoFullName.getText().toString().split("/")[0], repoFullName.getText().toString().split("/")[1]));
BottomSheetDialog dialog = new BottomSheetDialog(context);
dialog.setContentView(view);
dialog.show();
}
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
@Override
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
intentOpenInBrowser.putExtra("repoFullNameBrowser", repoFullName.getText());
context.startActivity(intentOpenInBrowser);
dialog.dismiss();
tinyDb.putBoolean("repoWatch", false);
Toasty.error(context, context.getString(R.string.genericApiStatusError));
});
}
});
repoStargazers.setOnClickListener(stargazers -> {
}
Intent intent = new Intent(context, RepoStargazersActivity.class);
intent.putExtra("repoFullNameForStars", repoFullName.getText());
context.startActivity(intent);
dialog.dismiss();
context.startActivity(intent);
});
});
repoWatchers.setOnClickListener(watchers -> {
reposDropdownMenu.setOnClickListener(v -> {
Intent intentW = new Intent(context, RepoWatchersActivity.class);
intentW.putExtra("repoFullNameForWatchers", repoFullName.getText());
context.startActivity(intentW);
dialog.dismiss();
final Context context = v.getContext();
});
@SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null);
});
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
TextView repoForksList = view.findViewById(R.id.repoForksList);
TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl);
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
}
}
bottomSheetHeader.setText(String.format("%s / %s", repoFullName.getText().toString().split("/")[0], repoFullName.getText().toString().split("/")[1]));
BottomSheetDialog dialog = new BottomSheetDialog(context);
dialog.setContentView(view);
dialog.show();
public MyReposListAdapter(Context mCtx, List<UserRepositories> reposListMain) {
this.mCtx = mCtx;
this.reposList = reposListMain;
reposListFull = new ArrayList<>(reposList);
}
repoCopyUrl.setOnClickListener(openInBrowser -> {
@NonNull
@Override
public MyReposListAdapter.MyReposViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_repositories, parent, false);
return new MyReposListAdapter.MyReposViewHolder(v);
}
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString());
assert clipboard != null;
clipboard.setPrimaryClip(clip);
@Override
public void onBindViewHolder(@NonNull MyReposListAdapter.MyReposViewHolder holder, int position) {
Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg));
dialog.dismiss();
});
UserRepositories currentItem = reposList.get(position);
holder.repoDescription.setVisibility(View.GONE);
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
ColorGenerator generator = ColorGenerator.MATERIAL;
int color = generator.getColor(currentItem.getName());
String firstCharacter = String.valueOf(currentItem.getName().charAt(0));
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
intentOpenInBrowser.putExtra("repoFullNameBrowser", repoFullName.getText());
context.startActivity(intentOpenInBrowser);
dialog.dismiss();
TextDrawable drawable = TextDrawable.builder()
.beginConfig()
.useFont(Typeface.DEFAULT)
.fontSize(18)
.toUpperCase()
.width(28)
.height(28)
.endConfig()
.buildRoundRect(firstCharacter, color, 3);
});
if (currentItem.getAvatar_url() != null) {
if (!currentItem.getAvatar_url().equals("")) {
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.imageAvatar);
} else {
holder.imageAvatar.setImageDrawable(drawable);
}
}
else {
holder.imageAvatar.setImageDrawable(drawable);
}
repoStargazers.setOnClickListener(stargazers -> {
holder.repoName.setText(currentItem.getName());
if (!currentItem.getDescription().equals("")) {
holder.repoDescription.setVisibility(View.VISIBLE);
holder.repoDescription.setText(currentItem.getDescription());
}
holder.repoFullName.setText(currentItem.getFullname());
if(currentItem.getPrivateFlag()) {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
holder.repoType.setText(R.string.strPrivate);
}
else {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
holder.repoType.setText(R.string.strPublic);
}
holder.repoStars.setText(currentItem.getStars_count());
holder.repoForks.setText(currentItem.getForks_count());
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
Intent intent = new Intent(context, RepoStargazersActivity.class);
intent.putExtra("repoFullNameForStars", repoFullName.getText());
context.startActivity(intent);
dialog.dismiss();
if(holder.isRepoAdmin == null) {
holder.isRepoAdmin = new CheckBox(mCtx);
}
holder.isRepoAdmin.setChecked(currentItem.getPermissions().isAdmin());
});
if(currentItem.isArchived()) {
holder.archiveRepo.setVisibility(View.VISIBLE);
}
else {
holder.archiveRepo.setVisibility(View.GONE);
}
repoWatchers.setOnClickListener(watchers -> {
}
Intent intentW = new Intent(context, RepoWatchersActivity.class);
intentW.putExtra("repoFullNameForWatchers", repoFullName.getText());
context.startActivity(intentW);
dialog.dismiss();
@Override
public int getItemCount() {
return reposList.size();
}
});
@Override
public Filter getFilter() {
return myReposFilter;
}
repoForksList.setOnClickListener(forks -> {
private Filter myReposFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<UserRepositories> filteredList = new ArrayList<>();
Intent intentW = new Intent(context, RepoForksActivity.class);
intentW.putExtra("repoFullNameForForks", repoFullName.getText());
context.startActivity(intentW);
dialog.dismiss();
if (constraint == null || constraint.length() == 0) {
filteredList.addAll(reposListFull);
} else {
String filterPattern = constraint.toString().toLowerCase().trim();
});
for (UserRepositories 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;
}
}
public MyReposListAdapter(Context mCtx, List<UserRepositories> reposListMain) {
this.mCtx = mCtx;
this.reposList = reposListMain;
reposListFull = new ArrayList<>(reposList);
}
@NonNull
@Override
public MyReposListAdapter.MyReposViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_repositories, parent, false);
return new MyReposListAdapter.MyReposViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull MyReposListAdapter.MyReposViewHolder holder, int position) {
UserRepositories currentItem = reposList.get(position);
holder.repoDescription.setVisibility(View.GONE);
holder.repoBranch.setText(currentItem.getDefault_branch());
holder.htmlUrl.setText(currentItem.getHtml_url());
ColorGenerator generator = ColorGenerator.MATERIAL;
int color = generator.getColor(currentItem.getName());
String firstCharacter = String.valueOf(currentItem.getName().charAt(0));
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28).endConfig().buildRoundRect(firstCharacter, color, 3);
if(currentItem.getAvatar_url() != null) {
if(!currentItem.getAvatar_url().equals("")) {
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.imageAvatar);
}
else {
holder.imageAvatar.setImageDrawable(drawable);
}
}
else {
holder.imageAvatar.setImageDrawable(drawable);
}
holder.repoName.setText(currentItem.getName());
if(!currentItem.getDescription().equals("")) {
holder.repoDescription.setVisibility(View.VISIBLE);
holder.repoDescription.setText(currentItem.getDescription());
}
holder.repoFullName.setText(currentItem.getFullname());
if(currentItem.getPrivateFlag()) {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock);
holder.repoType.setText(R.string.strPrivate);
}
else {
holder.repoPrivatePublic.setVisibility(View.GONE);
holder.repoType.setText(R.string.strPublic);
}
holder.repoStars.setText(currentItem.getStars_count());
holder.repoForks.setText(currentItem.getForks_count());
holder.repoOpenIssuesCount.setText(currentItem.getOpen_issues_count());
if(holder.isRepoAdmin == null) {
holder.isRepoAdmin = new CheckBox(mCtx);
}
holder.isRepoAdmin.setChecked(currentItem.getPermissions().isAdmin());
if(currentItem.isArchived()) {
holder.archiveRepo.setVisibility(View.VISIBLE);
}
else {
holder.archiveRepo.setVisibility(View.GONE);
}
}
@Override
public int getItemCount() {
return reposList.size();
}
@Override
public Filter getFilter() {
return myReposFilter;
}
private Filter myReposFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
List<UserRepositories> filteredList = new ArrayList<>();
if(constraint == null || constraint.length() == 0) {
filteredList.addAll(reposListFull);
}
else {
String filterPattern = constraint.toString().toLowerCase().trim();
for(UserRepositories 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;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
reposList.clear();
reposList.addAll((List) results.values);
notifyDataSetChanged();
}
};
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
reposList.clear();
reposList.addAll((List) results.values);
notifyDataSetChanged();
}
};
}

View File

@ -0,0 +1,156 @@
package org.mian.gitnex.adapters;
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.NotificationThread;
import java.util.List;
/**
* Author opyale
*/
public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdapter.NotificationsViewHolder> {
private Context context;
private List<NotificationThread> notificationThreads;
private OnMoreClickedListener onMoreClickedListener;
private OnNotificationClickedListener onNotificationClickedListener;
private TinyDB tinyDb;
public NotificationsAdapter(Context context, List<NotificationThread> notificationThreads, OnMoreClickedListener onMoreClickedListener, OnNotificationClickedListener onNotificationClickedListener) {
this.tinyDb = new TinyDB(context);
this.context = context;
this.notificationThreads = notificationThreads;
this.onMoreClickedListener = onMoreClickedListener;
this.onNotificationClickedListener = onNotificationClickedListener;
}
static class NotificationsViewHolder extends RecyclerView.ViewHolder {
private LinearLayout frame;
private TextView subject;
private TextView repository;
private ImageView type;
private ImageView pinned;
private ImageView more;
public NotificationsViewHolder(@NonNull View itemView) {
super(itemView);
frame = itemView.findViewById(R.id.frame);
subject = itemView.findViewById(R.id.subject);
repository = itemView.findViewById(R.id.repository);
type = itemView.findViewById(R.id.type);
pinned = itemView.findViewById(R.id.pinned);
more = itemView.findViewById(R.id.more);
}
}
@NonNull
@Override
public NotificationsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.list_notifications, parent, false);
return new NotificationsAdapter.NotificationsViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull NotificationsViewHolder holder, int position) {
NotificationThread notificationThread = notificationThreads.get(position);
String url = notificationThread.getSubject().getUrl();
String subjectId = "<font color='" + context.getResources().getColor(R.color.lightGray) + "'>" + context.getResources()
.getString(R.string.hash) + url.substring(url.lastIndexOf("/") + 1) + "</font>";
holder.subject.setText(Html.fromHtml(subjectId + " " + notificationThread.getSubject().getTitle()));
holder.repository.setText(notificationThread.getRepository().getFullname());
if(notificationThread.isPinned()) {
holder.pinned.setVisibility(View.VISIBLE);
}
else {
holder.pinned.setVisibility(View.GONE);
}
switch(notificationThread.getSubject().getType()) {
case "Pull":
holder.type.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_pull_request, null));
break;
case "Issue":
holder.type.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_issue, null));
break;
default:
holder.type.setImageDrawable(context.getResources().getDrawable(R.drawable.ic_question, null));
break;
}
holder.frame.setOnClickListener(v -> {
onNotificationClickedListener.onNotificationClicked(notificationThread);
String[] parts = notificationThread.getRepository().getFullname().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
if(count == 0) {
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", id);
}
else {
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", data.getRepositoryId());
}
});
holder.more.setOnClickListener(v -> onMoreClickedListener.onMoreClicked(notificationThread));
}
@Override
public int getItemCount() {
return notificationThreads.size();
}
public interface OnNotificationClickedListener {
void onNotificationClicked(NotificationThread notificationThread);
}
public interface OnMoreClickedListener {
void onMoreClicked(NotificationThread notificationThread);
}
}

View File

@ -1,7 +1,5 @@
package org.mian.gitnex.adapters;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
@ -12,12 +10,14 @@ import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.OrganizationDetailActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.models.UserOrganizations;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.UserOrganizations;
import java.util.ArrayList;
import java.util.List;

View File

@ -58,7 +58,7 @@ public class ProfileEmailsAdapter extends RecyclerView.Adapter<ProfileEmailsAdap
if(currentItem.getPrimary()) {
TextDrawable drawable = TextDrawable.builder()
.beginConfig()
.textColor(mCtx.getResources().getColor(R.color.white))
.textColor(mCtx.getResources().getColor(R.color.colorWhite))
.fontSize(36)
.width(220)
.height(60)

View File

@ -18,8 +18,8 @@ import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.helpers.ClickListener;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.PullRequests;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
import java.util.Locale;
@ -136,7 +136,7 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
tinyDb.putString("prHeadBranch", prHeadBranch.getText().toString());
tinyDb.putString("prIsFork", prIsFork.getText().toString());
tinyDb.putString("prForkFullName", prForkFullName.getText().toString());
tinyDb.putString("issueType", "pr");
tinyDb.putString("issueType", "Pull");
context.startActivity(intent);
});
@ -155,7 +155,7 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
tinyDb.putString("prHeadBranch", prHeadBranch.getText().toString());
tinyDb.putString("prIsFork", prIsFork.getText().toString());
tinyDb.putString("prForkFullName", prForkFullName.getText().toString());
tinyDb.putString("issueType", "pr");
tinyDb.putString("issueType", "Pull");
context.startActivity(intent);
});

View File

@ -22,8 +22,8 @@ import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.helpers.ClickListener;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TimeHelper;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.Releases;
import org.mian.gitnex.util.TinyDB;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@ -210,13 +210,13 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
if(holder.downloads.getVisibility() == View.GONE) {
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_arrow_down);
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_chevron_down);
holder.downloads.setVisibility(View.VISIBLE);
}
else {
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_arrow_right);
holder.downloadDropdownIcon.setImageResource(R.drawable.ic_chevron_right);
holder.downloads.setVisibility(View.GONE);
}

View File

@ -0,0 +1,396 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.OpenRepoInBrowserActivity;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.activities.RepoForksActivity;
import org.mian.gitnex.activities.RepoStargazersActivity;
import org.mian.gitnex.activities.RepoWatchersActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.UserRepositories;
import org.mian.gitnex.models.WatchInfo;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
/**
* Author M M Arif
*/
public class RepoForksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context ctx;
private final int TYPE_LOAD = 0;
private List<UserRepositories> forksList;
private OnLoadMoreListener loadMoreListener;
private boolean isLoading = false;
private boolean isMoreDataAvailable = true;
public RepoForksAdapter(Context ctx, List<UserRepositories> forksListMain) {
this.ctx = ctx;
this.forksList = forksListMain;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(ctx);
if(viewType == TYPE_LOAD) {
return new RepoForksAdapter.ForksHolder(inflater.inflate(R.layout.list_repositories, parent, false));
}
else {
return new LoadHolder(inflater.inflate(R.layout.row_load, parent, false));
}
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
if(position >= getItemCount() - 1 && isMoreDataAvailable && !isLoading && loadMoreListener != null) {
isLoading = true;
loadMoreListener.onLoadMore();
}
if(getItemViewType(position) == TYPE_LOAD) {
((RepoForksAdapter.ForksHolder) holder).bindData(forksList.get(position));
}
}
@Override
public int getItemViewType(int position) {
if(forksList.get(position).getName() != null) {
return TYPE_LOAD;
}
else {
return 1;
}
}
@Override
public int getItemCount() {
return forksList.size();
}
class ForksHolder extends RecyclerView.ViewHolder {
private ImageView image;
private TextView repoName;
private TextView repoDescription;
private TextView fullName;
private CheckBox isRepoAdmin;
private ImageView repoPrivatePublic;
private TextView repoStars;
private TextView repoForks;
private TextView repoOpenIssuesCount;
private TextView repoType;
private LinearLayout archiveRepo;
private TextView repoBranch;
private ImageView reposDropdownMenu;
ForksHolder(View itemView) {
super(itemView);
repoName = itemView.findViewById(R.id.repoName);
repoDescription = itemView.findViewById(R.id.repoDescription);
isRepoAdmin = itemView.findViewById(R.id.repoIsAdmin);
image = itemView.findViewById(R.id.imageAvatar);
fullName = itemView.findViewById(R.id.repoFullName);
repoPrivatePublic = itemView.findViewById(R.id.imageRepoType);
repoStars = itemView.findViewById(R.id.repoStars);
repoForks = itemView.findViewById(R.id.repoForks);
repoOpenIssuesCount = itemView.findViewById(R.id.repoOpenIssuesCount);
reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
repoType = itemView.findViewById(R.id.repoType);
archiveRepo = itemView.findViewById(R.id.archiveRepoFrame);
repoBranch = itemView.findViewById(R.id.repoBranch);
}
@SuppressLint("SetTextI18n")
void bindData(UserRepositories forksModel) {
repoDescription.setVisibility(View.GONE);
repoBranch.setText(forksModel.getDefault_branch());
ColorGenerator generator = ColorGenerator.MATERIAL;
int color = generator.getColor(forksModel.getName());
String firstCharacter = String.valueOf(forksModel.getName().charAt(0));
TextDrawable drawable = TextDrawable.builder().beginConfig().useFont(Typeface.DEFAULT).fontSize(18).toUpperCase().width(28).height(28)
.endConfig().buildRoundRect(firstCharacter, color, 3);
if(forksModel.getAvatar_url() != null) {
if(!forksModel.getAvatar_url().equals("")) {
PicassoService.getInstance(ctx).get().load(forksModel.getAvatar_url()).placeholder(R.drawable.loader_animated)
.transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(image);
}
else {
image.setImageDrawable(drawable);
}
}
else {
image.setImageDrawable(drawable);
}
repoName.setText(forksModel.getName());
if(!forksModel.getDescription().equals("")) {
repoDescription.setVisibility(View.VISIBLE);
repoDescription.setText(forksModel.getDescription());
}
fullName.setText(forksModel.getFullname());
if(forksModel.getPrivateFlag()) {
repoPrivatePublic.setImageResource(R.drawable.ic_lock);
repoType.setText(R.string.strPrivate);
}
else {
repoPrivatePublic.setVisibility(View.GONE);
repoType.setText(R.string.strPublic);
}
repoStars.setText(forksModel.getStars_count());
repoForks.setText(forksModel.getForks_count());
repoOpenIssuesCount.setText(forksModel.getOpen_issues_count());
if(isRepoAdmin == null) {
isRepoAdmin = new CheckBox(ctx);
}
isRepoAdmin.setChecked(forksModel.getPermissions().isAdmin());
if(forksModel.isArchived()) {
archiveRepo.setVisibility(View.VISIBLE);
}
else {
archiveRepo.setVisibility(View.GONE);
}
itemView.setOnClickListener(v -> {
Context context = v.getContext();
TextView repoFullName = v.findViewById(R.id.repoFullName);
TextView repoType_ = v.findViewById(R.id.repoType);
Intent intent = new Intent(context, RepoDetailActivity.class);
intent.putExtra("repoFullName", repoFullName.getText().toString());
TinyDB tinyDb = new TinyDB(context);
tinyDb.putString("repoFullName", repoFullName.getText().toString());
tinyDb.putString("repoType", repoType_.getText().toString());
//tinyDb.putBoolean("resumeIssues", true);
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
tinyDb.putString("repoBranch", repoBranch.getText().toString());
String[] parts = repoFullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
if(count == 0) {
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", id);
}
else {
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", data.getRepositoryId());
}
//store if user is watching this repo
{
final String instanceUrl = tinyDb.getString("instanceUrl");
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
WatchInfo watch = new WatchInfo();
Call<WatchInfo> call;
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
call.enqueue(new Callback<WatchInfo>() {
@Override
public void onResponse(@NonNull Call<WatchInfo> call, @NonNull retrofit2.Response<WatchInfo> response) {
if(response.isSuccessful()) {
assert response.body() != null;
tinyDb.putBoolean("repoWatch", response.body().getSubscribed());
}
else {
tinyDb.putBoolean("repoWatch", false);
if(response.code() != 404) {
Toasty.error(context, context.getString(R.string.genericApiStatusError));
}
}
}
@Override
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
tinyDb.putBoolean("repoWatch", false);
Toasty.error(context, context.getString(R.string.genericApiStatusError));
}
});
}
context.startActivity(intent);
});
reposDropdownMenu.setOnClickListener(v -> {
final Context context = v.getContext();
@SuppressLint("InflateParams") View view = LayoutInflater.from(context).inflate(R.layout.bottom_sheet_repository_in_list, null);
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
TextView repoForksList = view.findViewById(R.id.repoForksList);
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
bottomSheetHeader
.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1]));
BottomSheetDialog dialog = new BottomSheetDialog(context);
dialog.setContentView(view);
dialog.show();
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
intentOpenInBrowser.putExtra("repoFullNameBrowser", fullName.getText());
context.startActivity(intentOpenInBrowser);
dialog.dismiss();
});
repoStargazers.setOnClickListener(stargazers -> {
Intent intent = new Intent(context, RepoStargazersActivity.class);
intent.putExtra("repoFullNameForStars", fullName.getText());
context.startActivity(intent);
dialog.dismiss();
});
repoWatchers.setOnClickListener(watchers -> {
Intent intentW = new Intent(context, RepoWatchersActivity.class);
intentW.putExtra("repoFullNameForWatchers", fullName.getText());
context.startActivity(intentW);
dialog.dismiss();
});
repoForksList.setOnClickListener(watchers -> {
Intent intentW = new Intent(context, RepoForksActivity.class);
intentW.putExtra("repoFullNameForForks", fullName.getText());
context.startActivity(intentW);
dialog.dismiss();
});
});
}
}
static class LoadHolder extends RecyclerView.ViewHolder {
LoadHolder(View itemView) {
super(itemView);
}
}
public void setMoreDataAvailable(boolean moreDataAvailable) {
isMoreDataAvailable = moreDataAvailable;
}
public void notifyDataChanged() {
notifyDataSetChanged();
isLoading = false;
}
public interface OnLoadMoreListener {
void onLoadMore();
}
public void setLoadMoreListener(RepoForksAdapter.OnLoadMoreListener loadMoreListener) {
this.loadMoreListener = loadMoreListener;
}
public void updateList(List<UserRepositories> list) {
forksList = list;
notifyDataSetChanged();
}
}

View File

@ -12,8 +12,8 @@ import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
/**

View File

@ -12,8 +12,8 @@ import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
/**

View File

@ -1,6 +1,8 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
@ -23,15 +25,19 @@ import org.mian.gitnex.activities.OpenRepoInBrowserActivity;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.activities.RepoStargazersActivity;
import org.mian.gitnex.activities.RepoWatchersActivity;
import org.mian.gitnex.activities.RepoForksActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.UserRepositories;
import org.mian.gitnex.models.WatchInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
@ -58,6 +64,8 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
private TextView repoOpenIssuesCount;
private TextView repoType;
private LinearLayout archiveRepo;
private TextView repoBranch;
private TextView htmlUrl;
private ReposViewHolder(View itemView) {
@ -74,6 +82,8 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
repoType = itemView.findViewById(R.id.repoType);
archiveRepo = itemView.findViewById(R.id.archiveRepoFrame);
repoBranch = itemView.findViewById(R.id.repoBranch);
htmlUrl = itemView.findViewById(R.id.htmlUrl);
itemView.setOnClickListener(v -> {
@ -89,13 +99,35 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
tinyDb.putString("repoType", repoType_.getText().toString());
//tinyDb.putBoolean("resumeIssues", true);
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
tinyDb.putString("repoBranch", repoBranch.getText().toString());
String[] parts = repoFullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
if(count == 0) {
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", id);
}
else {
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", data.getRepositoryId());
}
//store if user is watching this repo
{
final String instanceUrl = tinyDb.getString("instanceUrl");
String[] parts = repoFullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
WatchInfo watch = new WatchInfo();
@ -120,7 +152,7 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
if(response.code() != 404) {
Toasty.info(context, context.getString(R.string.genericApiStatusError));
Toasty.error(context, context.getString(R.string.genericApiStatusError));
}
@ -132,10 +164,11 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
tinyDb.putBoolean("repoWatch", false);
Toasty.info(context, context.getString(R.string.genericApiStatusError));
Toasty.error(context, context.getString(R.string.genericApiStatusError));
}
});
}
context.startActivity(intent);
@ -151,6 +184,8 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
TextView repoForksList = view.findViewById(R.id.repoForksList);
TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl);
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
bottomSheetHeader.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1]));
@ -158,6 +193,17 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
dialog.setContentView(view);
dialog.show();
repoCopyUrl.setOnClickListener(openInBrowser -> {
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString());
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg));
dialog.dismiss();
});
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
@ -185,6 +231,15 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
});
repoForksList.setOnClickListener(forks -> {
Intent intentW = new Intent(context, RepoForksActivity.class);
intentW.putExtra("repoFullNameForForks", fullName.getText());
context.startActivity(intentW);
dialog.dismiss();
});
});
}
@ -211,6 +266,8 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
UserRepositories currentItem = reposList.get(position);
holder.repoDescription.setVisibility(View.GONE);
holder.repoBranch.setText(currentItem.getDefault_branch());
holder.htmlUrl.setText(currentItem.getHtml_url());
ColorGenerator generator = ColorGenerator.MATERIAL;
int color = generator.getColor(currentItem.getName());
@ -237,11 +294,11 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
}
holder.fullName.setText(currentItem.getFullname());
if(currentItem.getPrivateFlag()) {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock);
holder.repoType.setText(R.string.strPrivate);
}
else {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
holder.repoPrivatePublic.setVisibility(View.GONE);
holder.repoType.setText(R.string.strPublic);
}
holder.repoStars.setText(currentItem.getStars_count());

View File

@ -1,6 +1,8 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
@ -13,6 +15,8 @@ import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.google.android.material.bottomsheet.BottomSheetDialog;
@ -21,17 +25,19 @@ import org.mian.gitnex.activities.OpenRepoInBrowserActivity;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.activities.RepoStargazersActivity;
import org.mian.gitnex.activities.RepoWatchersActivity;
import org.mian.gitnex.activities.RepoForksActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.UserRepositories;
import org.mian.gitnex.models.WatchInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
@ -58,6 +64,8 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
private TextView repoOpenIssuesCount;
private TextView repoType;
private LinearLayout archiveRepo;
private TextView repoBranch;
private TextView htmlUrl;
private OrgReposViewHolder(View itemView) {
super(itemView);
@ -73,6 +81,8 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
repoType = itemView.findViewById(R.id.repoType);
archiveRepo = itemView.findViewById(R.id.archiveRepoFrame);
repoBranch = itemView.findViewById(R.id.repoBranch);
htmlUrl = itemView.findViewById(R.id.htmlUrl);
itemView.setOnClickListener(v -> {
@ -86,16 +96,36 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
tinyDb.putString("repoType", repoType.getText().toString());
//tinyDb.putBoolean("resumeIssues", true);
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
tinyDb.putString("repoBranch", repoBranch.getText().toString());
String[] parts = fullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
if(count == 0) {
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", id);
}
else {
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", data.getRepositoryId());
}
//store if user is watching this repo
{
final String instanceUrl = tinyDb.getString("instanceUrl");
String[] parts = fullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
WatchInfo watch = new WatchInfo();
final String instanceUrl = tinyDb.getString("instanceUrl");
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
Call<WatchInfo> call;
@ -117,7 +147,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
if(response.code() != 404) {
Toasty.info(context, context.getString(R.string.genericApiStatusError));
Toasty.error(context, context.getString(R.string.genericApiStatusError));
}
@ -129,10 +159,11 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
tinyDb.putBoolean("repoWatch", false);
Toasty.info(context, context.getString(R.string.genericApiStatusError));
Toasty.error(context, context.getString(R.string.genericApiStatusError));
}
});
}
context.startActivity(intent);
@ -148,6 +179,8 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
TextView repoForksList = view.findViewById(R.id.repoForksList);
TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl);
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
bottomSheetHeader.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1]));
@ -155,6 +188,17 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
dialog.setContentView(view);
dialog.show();
repoCopyUrl.setOnClickListener(openInBrowser -> {
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString());
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg));
dialog.dismiss();
});
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
@ -164,7 +208,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
});
repoStargazers.setOnClickListener(openInBrowser -> {
repoStargazers.setOnClickListener(stargazers -> {
Intent intent = new Intent(context, RepoStargazersActivity.class);
intent.putExtra("repoFullNameForStars", fullName.getText());
@ -173,7 +217,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
});
repoWatchers.setOnClickListener(openInBrowser -> {
repoWatchers.setOnClickListener(watchers -> {
Intent intentW = new Intent(context, RepoWatchersActivity.class);
intentW.putExtra("repoFullNameForWatchers", fullName.getText());
@ -182,6 +226,15 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
});
repoForksList.setOnClickListener(forks -> {
Intent intentW = new Intent(context, RepoForksActivity.class);
intentW.putExtra("repoFullNameForForks", fullName.getText());
context.startActivity(intentW);
dialog.dismiss();
});
});
}
@ -206,6 +259,8 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
UserRepositories currentItem = reposList.get(position);
holder.repoDescription.setVisibility(View.GONE);
holder.repoBranch.setText(currentItem.getDefault_branch());
holder.htmlUrl.setText(currentItem.getHtml_url());
ColorGenerator generator = ColorGenerator.MATERIAL;
int color = generator.getColor(currentItem.getName());
@ -239,11 +294,11 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
}
holder.fullName.setText(currentItem.getFullname());
if(currentItem.getPrivateFlag()) {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock);
holder.repoType.setText(R.string.strPrivate);
}
else {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
holder.repoPrivatePublic.setVisibility(View.GONE);
holder.repoType.setText(R.string.strPublic);
}
holder.repoStars.setText(currentItem.getStars_count());

View File

@ -1,6 +1,8 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
@ -13,6 +15,8 @@ import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.google.android.material.bottomsheet.BottomSheetDialog;
@ -21,17 +25,19 @@ import org.mian.gitnex.activities.OpenRepoInBrowserActivity;
import org.mian.gitnex.activities.RepoDetailActivity;
import org.mian.gitnex.activities.RepoStargazersActivity;
import org.mian.gitnex.activities.RepoWatchersActivity;
import org.mian.gitnex.activities.RepoForksActivity;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.database.api.RepositoriesApi;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.UserRepositories;
import org.mian.gitnex.models.WatchInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.Objects;
import retrofit2.Call;
import retrofit2.Callback;
@ -58,6 +64,8 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
private TextView repoOpenIssuesCount;
private TextView repoType;
private LinearLayout archiveRepo;
private TextView repoBranch;
private TextView htmlUrl;
private StarredReposViewHolder(View itemView) {
super(itemView);
@ -73,6 +81,8 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
ImageView reposDropdownMenu = itemView.findViewById(R.id.reposDropdownMenu);
repoType = itemView.findViewById(R.id.repoType);
archiveRepo = itemView.findViewById(R.id.archiveRepoFrame);
repoBranch = itemView.findViewById(R.id.repoBranch);
htmlUrl = itemView.findViewById(R.id.htmlUrl);
itemView.setOnClickListener(v -> {
@ -86,13 +96,35 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
tinyDb.putString("repoType", repoType.getText().toString());
//tinyDb.putBoolean("resumeIssues", true);
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
tinyDb.putString("repoBranch", repoBranch.getText().toString());
String[] parts = fullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
RepositoriesApi repositoryData = new RepositoriesApi(context);
//RepositoriesRepository.deleteRepositoriesByAccount(currentActiveAccountId);
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
if(count == 0) {
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", id);
}
else {
Repository data = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
tinyDb.putLong("repositoryId", data.getRepositoryId());
}
//store if user is watching this repo
{
final String instanceUrl = tinyDb.getString("instanceUrl");
String[] parts = fullName.getText().toString().split("/");
final String repoOwner = parts[0];
final String repoName = parts[1];
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
WatchInfo watch = new WatchInfo();
@ -133,6 +165,7 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
}
});
}
context.startActivity(intent);
@ -149,6 +182,8 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
TextView repoOpenInBrowser = view.findViewById(R.id.repoOpenInBrowser);
TextView repoStargazers = view.findViewById(R.id.repoStargazers);
TextView repoWatchers = view.findViewById(R.id.repoWatchers);
TextView repoForksList = view.findViewById(R.id.repoForksList);
TextView repoCopyUrl = view.findViewById(R.id.repoCopyUrl);
TextView bottomSheetHeader = view.findViewById(R.id.bottomSheetHeader);
bottomSheetHeader.setText(String.format("%s / %s", fullName.getText().toString().split("/")[0], fullName.getText().toString().split("/")[1]));
@ -156,6 +191,17 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
dialog.setContentView(view);
dialog.show();
repoCopyUrl.setOnClickListener(openInBrowser -> {
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(context).getSystemService(Context.CLIPBOARD_SERVICE);
ClipData clip = ClipData.newPlainText("repoUrl", htmlUrl.getText().toString());
assert clipboard != null;
clipboard.setPrimaryClip(clip);
Toasty.info(context, context.getString(R.string.copyIssueUrlToastMsg));
dialog.dismiss();
});
repoOpenInBrowser.setOnClickListener(openInBrowser -> {
Intent intentOpenInBrowser = new Intent(context, OpenRepoInBrowserActivity.class);
@ -183,6 +229,15 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
});
repoForksList.setOnClickListener(forks -> {
Intent intentW = new Intent(context, RepoForksActivity.class);
intentW.putExtra("repoFullNameForForks", fullName.getText());
context.startActivity(intentW);
dialog.dismiss();
});
});
}
@ -207,6 +262,8 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
UserRepositories currentItem = reposList.get(position);
holder.repoDescription.setVisibility(View.GONE);
holder.repoBranch.setText(currentItem.getDefault_branch());
holder.htmlUrl.setText(currentItem.getHtml_url());
ColorGenerator generator = ColorGenerator.MATERIAL;
int color = generator.getColor(currentItem.getName());
@ -240,11 +297,11 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
}
holder.fullName.setText(currentItem.getFullname());
if(currentItem.getPrivateFlag()) {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock_bold);
holder.repoPrivatePublic.setImageResource(R.drawable.ic_lock);
holder.repoType.setText(R.string.strPrivate);
}
else {
holder.repoPrivatePublic.setImageResource(R.drawable.ic_public);
holder.repoPrivatePublic.setVisibility(View.GONE);
holder.repoType.setText(R.string.strPublic);
}
holder.repoStars.setText(currentItem.getStars_count());

View File

@ -11,10 +11,9 @@ import android.widget.ImageView;
import android.widget.TextView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.helpers.FontsOverride;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
/**

View File

@ -0,0 +1,155 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import java.util.List;
import io.mikael.urlbuilder.UrlBuilder;
/**
* Author M M Arif
*/
public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapter.UserAccountsViewHolder> {
private List<UserAccount> userAccountsList;
private Context mCtx;
private TinyDB tinyDB;
class UserAccountsViewHolder extends RecyclerView.ViewHolder {
private TextView accountUrl;
private TextView userId;
private ImageView activeAccount;
private ImageView deleteAccount;
private ImageView repoAvatar;
private TextView accountId;
private TextView accountName;
private UserAccountsViewHolder(View itemView) {
super(itemView);
accountUrl = itemView.findViewById(R.id.accountUrl);
userId = itemView.findViewById(R.id.userId);
activeAccount = itemView.findViewById(R.id.activeAccount);
deleteAccount = itemView.findViewById(R.id.deleteAccount);
repoAvatar = itemView.findViewById(R.id.repoAvatar);
accountId = itemView.findViewById(R.id.accountId);
accountName = itemView.findViewById(R.id.accountName);
deleteAccount.setOnClickListener(itemDelete -> {
new AlertDialog.Builder(mCtx)
.setIcon(mCtx.getDrawable(R.drawable.ic_delete))
.setTitle(mCtx.getResources().getString(R.string.removeAccountPopupTitle))
.setMessage(mCtx.getResources().getString(R.string.removeAccountPopupMessage))
.setPositiveButton(mCtx.getResources().getString(R.string.removeButton), (dialog, which) -> {
updateLayoutByPosition(getAdapterPosition());
UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx);
userAccountsApi.deleteAccount(Integer.parseInt(accountId.getText().toString()));
}).setNeutralButton(mCtx.getResources().getString(R.string.cancelButton), null)
.show();
});
itemView.setOnClickListener(itemEdit -> {
String accountNameSwitch = accountName.getText().toString();
UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx);
UserAccount userAccount = userAccountsApi.getAccountData(accountNameSwitch);
if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) {
String url = UrlBuilder.fromString(userAccount.getInstanceUrl())
.withPath("/")
.toString();
tinyDB.putString("loginUid", userAccount.getUserName());
tinyDB.putString("userLogin", userAccount.getUserName());
tinyDB.putString(userAccount.getUserName() + "-token", userAccount.getToken());
tinyDB.putString("instanceUrl", userAccount.getInstanceUrl());
tinyDB.putInt("currentActiveAccountId", userAccount.getAccountId());
Toasty.success(mCtx, mCtx.getResources().getString(R.string.switchAccountSuccess, userAccount.getUserName(), url));
((Activity) mCtx).recreate();
}
});
}
}
public UserAccountsAdapter(Context mCtx, List<UserAccount> userAccountsListMain) {
this.mCtx = mCtx;
this.userAccountsList = userAccountsListMain;
}
private void updateLayoutByPosition(int position) {
userAccountsList.remove(position);
notifyItemRemoved(position);
notifyItemRangeChanged(position, userAccountsList.size());
Toasty.success(mCtx, mCtx.getResources().getString(R.string.accountDeletedMessage));
}
@NonNull
@Override
public UserAccountsAdapter.UserAccountsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_user_accounts, parent, false);
return new UserAccountsViewHolder(v);
}
@SuppressLint("DefaultLocale")
@Override
public void onBindViewHolder(@NonNull UserAccountsAdapter.UserAccountsViewHolder holder, int position) {
UserAccount currentItem = userAccountsList.get(position);
tinyDB = new TinyDB(mCtx);
String url = UrlBuilder.fromString(currentItem.getInstanceUrl())
.withPath("/")
.toString();
holder.accountId.setText(String.valueOf(currentItem.getAccountId()));
holder.accountName.setText(currentItem.getAccountName());
holder.userId.setText(String.format("@%s", currentItem.getUserName()));
holder.accountUrl.setText(url);
PicassoService.getInstance(mCtx).get().load(url + "img/favicon.png").placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.repoAvatar);
if(tinyDB.getInt("currentActiveAccountId") == currentItem.getAccountId()) {
holder.activeAccount.setVisibility(View.VISIBLE);
}
else {
holder.deleteAccount.setVisibility(View.VISIBLE);
}
}
@Override
public int getItemCount() {
return userAccountsList.size();
}
}

View File

@ -0,0 +1,72 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import java.util.List;
import io.mikael.urlbuilder.UrlBuilder;
/**
* Author M M Arif
*/
public class UserAccountsListDialogAdapter extends ArrayAdapter<UserAccount> {
private final Context mCtx;
private final List<UserAccount> userAccountsList;
public UserAccountsListDialogAdapter(@NonNull Context mCtx, int resource, @NonNull List<UserAccount> objects) {
super(mCtx, resource, objects);
userAccountsList = objects;
this.mCtx = mCtx;
}
@SuppressLint("ViewHolder")
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mCtx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
assert inflater != null;
View rowView = inflater.inflate(R.layout.custom_user_accounts_list, parent, false);
TinyDB tinyDB = new TinyDB(mCtx);
ImageView profileImage = rowView.findViewById(R.id.profileImage);
TextView userName = rowView.findViewById(R.id.userName);
TextView accountUrl = rowView.findViewById(R.id.accountUrl);
ImageView activeAccount = rowView.findViewById(R.id.activeAccount);
UserAccount currentItem = userAccountsList.get(position);
String url = UrlBuilder.fromString(currentItem.getInstanceUrl())
.withPath("/")
.toString();
userName.setText(currentItem.getUserName());
accountUrl.setText(url);
if(tinyDB.getInt("currentActiveAccountId") == currentItem.getAccountId()) {
activeAccount.setVisibility(View.VISIBLE);
}
PicassoService
.getInstance(mCtx).get().load(url + "img/favicon.png").placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(profileImage);
return rowView;
}
}

View File

@ -0,0 +1,147 @@
package org.mian.gitnex.adapters;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.clients.PicassoService;
import org.mian.gitnex.database.api.UserAccountsApi;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.fragments.UserAccountsFragment;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import java.util.List;
import io.mikael.urlbuilder.UrlBuilder;
/**
* Author M M Arif
*/
public class UserAccountsNavAdapter extends RecyclerView.Adapter<UserAccountsNavAdapter.UserAccountsViewHolder> {
private static DrawerLayout drawer;
private List<UserAccount> userAccountsList;
private Context mCtx;
private TextView toolbarTitle;
public UserAccountsNavAdapter(Context mCtx, List<UserAccount> userAccountsListMain, DrawerLayout drawerLayout, TextView toolbarTitle) {
this.mCtx = mCtx;
this.userAccountsList = userAccountsListMain;
drawer = drawerLayout;
this.toolbarTitle = toolbarTitle;
}
class UserAccountsViewHolder extends RecyclerView.ViewHolder {
private ImageView userAccountAvatar;
private UserAccountsViewHolder(View itemView) {
super(itemView);
userAccountAvatar = itemView.findViewById(R.id.userAccountAvatar);
itemView.setOnClickListener(item -> {
customDialogUserAccountsList(userAccountsList);
drawer.closeDrawers();
});
}
}
@NonNull
@Override
public UserAccountsNavAdapter.UserAccountsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.nav_user_accounts, parent, false);
return new UserAccountsViewHolder(v);
}
@SuppressLint("DefaultLocale")
@Override
public void onBindViewHolder(@NonNull UserAccountsNavAdapter.UserAccountsViewHolder holder, int position) {
UserAccount currentItem = userAccountsList.get(position);
String url = UrlBuilder.fromString(currentItem.getInstanceUrl())
.withPath("/")
.toString();
PicassoService
.getInstance(mCtx).get().load(url + "img/favicon.png").placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.userAccountAvatar);
}
@Override
public int getItemCount() {
return userAccountsList.size();
}
private void customDialogUserAccountsList(List<UserAccount> allAccountsList) {
TinyDB tinyDB = new TinyDB(mCtx);
Dialog dialog = new Dialog(mCtx);
dialog.setContentView(R.layout.custom_user_accounts_dialog);
ListView listView = dialog.findViewById(R.id.accountsList);
TextView manageAccounts = dialog.findViewById(R.id.manageAccounts);
if (dialog.getWindow() != null) {
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
manageAccounts.setOnClickListener(item -> {
toolbarTitle.setText(mCtx.getResources().getString(R.string.pageTitleUserAccounts));
AppCompatActivity activity = (AppCompatActivity) mCtx;
activity.getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new UserAccountsFragment()).commit();
dialog.dismiss();
});
UserAccountsListDialogAdapter arrayAdapter = new UserAccountsListDialogAdapter(mCtx, R.layout.custom_user_accounts_list, allAccountsList);
listView.setAdapter(arrayAdapter);
listView.setOnItemClickListener((adapterView, view, which, l) -> {
String accountNameSwitch = allAccountsList.get(which).getAccountName();
UserAccountsApi userAccountsApi = new UserAccountsApi(mCtx);
UserAccount userAccount = userAccountsApi.getAccountData(accountNameSwitch);
if(tinyDB.getInt("currentActiveAccountId") != userAccount.getAccountId()) {
String url = UrlBuilder.fromString(userAccount.getInstanceUrl())
.withPath("/")
.toString();
tinyDB.putString("loginUid", userAccount.getUserName());
tinyDB.putString("userLogin", userAccount.getUserName());
tinyDB.putString(userAccount.getUserName() + "-token", userAccount.getToken());
tinyDB.putString("instanceUrl", userAccount.getInstanceUrl());
tinyDB.putInt("currentActiveAccountId", userAccount.getAccountId());
Toasty.success(mCtx, mCtx.getResources().getString(R.string.switchAccountSuccess, userAccount.getUserName(), url));
((Activity) mCtx).recreate();
dialog.dismiss();
}
});
dialog.show();
}
}

View File

@ -9,6 +9,9 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;
import org.mian.gitnex.R;
import org.mian.gitnex.actions.CollaboratorActions;
import org.mian.gitnex.clients.PicassoService;
@ -16,13 +19,10 @@ import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.models.Collaborators;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.RecyclerView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

View File

@ -14,9 +14,9 @@ import org.mian.gitnex.clients.RetrofitClient;
import org.mian.gitnex.helpers.AlertDialogs;
import org.mian.gitnex.helpers.Authorization;
import org.mian.gitnex.helpers.RoundedTransformation;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.Toasty;
import org.mian.gitnex.models.UserInfo;
import org.mian.gitnex.util.TinyDB;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;

View File

@ -2,10 +2,10 @@ package org.mian.gitnex.clients;
import android.content.Context;
import android.util.Log;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.FilesData;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.io.File;
import java.security.SecureRandom;
import javax.net.ssl.HttpsURLConnection;

View File

@ -2,12 +2,12 @@ package org.mian.gitnex.clients;
import android.content.Context;
import android.util.Log;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.FilesData;
import org.mian.gitnex.helpers.TinyDB;
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
import org.mian.gitnex.interfaces.ApiInterface;
import org.mian.gitnex.interfaces.WebInterface;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import java.io.File;
import java.security.SecureRandom;
import javax.net.ssl.HttpsURLConnection;

View File

@ -0,0 +1,126 @@
package org.mian.gitnex.database.api;
import android.content.Context;
import android.util.Log;
import androidx.lifecycle.LiveData;
import org.mian.gitnex.database.dao.DraftsDao;
import org.mian.gitnex.database.db.GitnexDatabase;
import org.mian.gitnex.database.models.Draft;
import org.mian.gitnex.database.models.DraftWithRepository;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import java.util.List;
/**
* Author M M Arif
*/
public class DraftsApi {
private static DraftsDao draftsDao;
private static long draftId;
private static Integer checkDraftFlag;
public DraftsApi(Context context) {
GitnexDatabase db;
db = GitnexDatabase.getDatabaseInstance(context);
draftsDao = db.draftsDao();
}
public long insertDraft(int repositoryId, int draftAccountId, int issueId, String draftText, String draftType, String commentId) {
Draft draft = new Draft();
draft.setDraftRepositoryId(repositoryId);
draft.setDraftAccountId(draftAccountId);
draft.setIssueId(issueId);
draft.setDraftText(draftText);
draft.setDraftType(draftType);
draft.setCommentId(draftType);
return insertDraftAsyncTask(draft);
}
private static long insertDraftAsyncTask(final Draft draft) {
try {
Thread thread = new Thread(() -> draftId = draftsDao.insertDraft(draft));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.draftsRepository, e.toString());
}
return draftId;
}
public long getDraftIdAsync(int issueId, int draftRepositoryId) {
try {
Thread thread = new Thread(() -> draftId = draftsDao.getDraftId(issueId, draftRepositoryId));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.draftsRepository, e.toString());
}
return draftId;
}
public Integer checkDraft(int issueId, int draftRepositoryId, String commentId) {
try {
Thread thread = new Thread(() -> checkDraftFlag = draftsDao.checkDraftDao(issueId, draftRepositoryId, commentId));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.draftsRepository, e.toString());
}
return checkDraftFlag;
}
public LiveData<List<DraftWithRepository>> getDrafts(int accountId) {
return draftsDao.fetchAllDrafts(accountId);
}
public LiveData<Draft> getDraftByIssueId(int issueId) {
return draftsDao.fetchDraftByIssueId(issueId);
}
public void deleteSingleDraft(final int draftId) {
final LiveData<Draft> draft = draftsDao.fetchDraftById(draftId);
if(draft != null) {
new Thread(() -> draftsDao.deleteByDraftId(draftId)).start();
}
}
public static void deleteAllDrafts(final int accountId) {
new Thread(() -> draftsDao.deleteAllDrafts(accountId)).start();
}
public static void updateDraft(final String draftText, final int draftId, final String commentId) {
new Thread(() -> draftsDao.updateDraft(draftText, draftId, commentId)).start();
}
public static void updateDraftByIssueIdAsyncTask(final String draftText, final int issueId, final int draftRepositoryId, final String commentId) {
new Thread(() -> draftsDao.updateDraftByIssueId(draftText, issueId, draftRepositoryId, commentId)).start();
}
}

View File

@ -0,0 +1,140 @@
package org.mian.gitnex.database.api;
import android.content.Context;
import android.util.Log;
import androidx.lifecycle.LiveData;
import org.mian.gitnex.database.dao.RepositoriesDao;
import org.mian.gitnex.database.db.GitnexDatabase;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import java.util.List;
/**
* Author M M Arif
*/
public class RepositoriesApi {
private static RepositoriesDao repositoriesDao;
private static long repositoryId;
private static Repository repository;
private static Integer checkRepository;
public RepositoriesApi(Context context) {
GitnexDatabase db;
db = GitnexDatabase.getDatabaseInstance(context);
repositoriesDao = db.repositoriesDao();
}
public long insertRepository(int repoAccountId, String repositoryOwner, String repositoryName) {
Repository repository = new Repository();
repository.setRepoAccountId(repoAccountId);
repository.setRepositoryOwner(repositoryOwner);
repository.setRepositoryName(repositoryName);
return insertRepositoryAsyncTask(repository);
}
public long insertRepositoryAsyncTask(Repository repository) {
try {
Thread thread = new Thread(() -> repositoryId = repositoriesDao.newRepository(repository));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return repositoryId;
}
public Repository getRepository(int repoAccountId, String repositoryOwner, String repositoryName) {
try {
Thread thread = new Thread(() -> repository = repositoriesDao.getSingleRepositoryDao(repoAccountId, repositoryOwner, repositoryName));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return repository;
}
public LiveData<List<Repository>> getAllRepositories() {
return repositoriesDao.fetchAllRepositories();
}
public LiveData<List<Repository>> getAllRepositoriesByAccount(int repoAccountId) {
return repositoriesDao.getAllRepositoriesByAccountDao(repoAccountId);
}
public Integer checkRepository(int repoAccountId, String repositoryOwner, String repositoryName) {
try {
Thread thread = new Thread(() -> checkRepository = repositoriesDao.checkRepositoryDao(repoAccountId, repositoryOwner, repositoryName));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return checkRepository;
}
public Repository fetchRepositoryById(int repositoryId) {
try {
Thread thread = new Thread(() -> repository = repositoriesDao.fetchRepositoryByIdDao(repositoryId));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return repository;
}
public Repository fetchRepositoryByAccountIdByRepositoryId(int repositoryId, int repoAccountId) {
try {
Thread thread = new Thread(() -> repository = repositoriesDao.fetchRepositoryByAccountIdByRepositoryIdDao(repositoryId, repoAccountId));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
}
return repository;
}
public static void deleteRepositoriesByAccount(final int repoAccountId) {
new Thread(() -> repositoriesDao.deleteRepositoriesByAccount(repoAccountId)).start();
}
public static void deleteRepository(final int repositoryId) {
new Thread(() -> repositoriesDao.deleteRepository(repositoryId)).start();
}
}

View File

@ -0,0 +1,115 @@
package org.mian.gitnex.database.api;
import android.content.Context;
import android.util.Log;
import androidx.lifecycle.LiveData;
import org.mian.gitnex.database.dao.UserAccountsDao;
import org.mian.gitnex.database.db.GitnexDatabase;
import org.mian.gitnex.database.models.UserAccount;
import org.mian.gitnex.helpers.StaticGlobalVariables;
import java.util.List;
/**
* Author M M Arif
*/
public class UserAccountsApi {
private static UserAccountsDao userAccountsDao;
private static UserAccount userAccount;
private static Integer checkAccount;
private static long accountId;
public UserAccountsApi(Context context) {
GitnexDatabase db;
db = GitnexDatabase.getDatabaseInstance(context);
userAccountsDao = db.userAccountsDao();
}
public long insertNewAccount(String accountName, String instanceUrl, String userName, String token, String serverVersion) {
UserAccount userAccount = new UserAccount();
userAccount.setAccountName(accountName);
userAccount.setInstanceUrl(instanceUrl);
userAccount.setUserName(userName);
userAccount.setToken(token);
userAccount.setServerVersion(serverVersion);
return insertNewAccountAsync(userAccount);
}
private static long insertNewAccountAsync(final UserAccount userAccount) {
try {
Thread thread = new Thread(() -> accountId = userAccountsDao.newAccount(userAccount));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.userAccountsRepository, e.toString());
}
return accountId;
}
public static void updateServerVersion(final String serverVersion, final int accountId) {
new Thread(() -> userAccountsDao.updateServerVersion(serverVersion, accountId)).start();
}
public void updateToken(final int accountId, final String token) {
new Thread(() -> userAccountsDao.updateAccountToken(accountId, token)).start();
}
public void updateTokenByAccountName(final String accountName, final String token) {
new Thread(() -> userAccountsDao.updateAccountTokenByAccountName(accountName, token)).start();
}
public UserAccount getAccountData(String accountName) {
try {
Thread thread = new Thread(() -> userAccount = userAccountsDao.fetchRowByAccount_(accountName));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.userAccountsRepository, e.toString());
}
return userAccount;
}
public Integer getCount(String accountName) {
try {
Thread thread = new Thread(() -> checkAccount = userAccountsDao.getCount(accountName));
thread.start();
thread.join();
}
catch(InterruptedException e) {
Log.e(StaticGlobalVariables.userAccountsRepository, e.toString());
}
return checkAccount;
}
public LiveData<List<UserAccount>> getAllAccounts() {
return userAccountsDao.fetchAllAccounts();
}
public void deleteAccount(final int accountId) {
new Thread(() -> userAccountsDao.deleteAccount(accountId)).start();
}
}

View File

@ -0,0 +1,56 @@
package org.mian.gitnex.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import org.mian.gitnex.database.models.Draft;
import org.mian.gitnex.database.models.DraftWithRepository;
import java.util.List;
/**
* Author M M Arif
*/
@Dao
public interface DraftsDao {
@Insert
long insertDraft(Draft drafts);
@Query("SELECT * FROM Drafts JOIN Repositories ON Repositories.repositoryId = Drafts.draftRepositoryId WHERE draftAccountId = :accountId" +
" ORDER BY " +
"draftId DESC")
LiveData<List<DraftWithRepository>> fetchAllDrafts(int accountId);
@Query("SELECT * FROM Drafts WHERE draftAccountId = :accountId ORDER BY draftId DESC")
LiveData<List<Draft>> fetchDrafts(int accountId);
@Query("SELECT * FROM Drafts WHERE draftAccountId = :accountId and draftRepositoryId = :repositoryId")
LiveData<Draft> fetchSingleDraftByAccountIdAndRepositoryId(int accountId, int repositoryId);
@Query("SELECT * FROM Drafts WHERE draftId = :draftId")
LiveData<Draft> fetchDraftById(int draftId);
@Query("SELECT * FROM Drafts WHERE issueId = :issueId")
LiveData<Draft> fetchDraftByIssueId(int issueId);
@Query("SELECT count(draftId) FROM Drafts WHERE issueId = :issueId AND draftRepositoryId = :draftRepositoryId AND commentId = :commentId")
Integer checkDraftDao(int issueId, int draftRepositoryId, String commentId);
@Query("UPDATE Drafts SET draftText = :draftText, commentId = :commentId WHERE draftId = :draftId")
void updateDraft(String draftText, int draftId, String commentId);
@Query("UPDATE Drafts SET draftText = :draftText WHERE issueId = :issueId AND draftRepositoryId = :draftRepositoryId AND commentId = :commentId")
void updateDraftByIssueId(String draftText, int issueId, int draftRepositoryId, String commentId);
@Query("SELECT draftId FROM Drafts WHERE issueId = :issueId AND draftRepositoryId = :draftRepositoryId")
Integer getDraftId(int issueId, int draftRepositoryId);
@Query("DELETE FROM Drafts WHERE draftId = :draftId")
void deleteByDraftId(int draftId);
@Query("DELETE FROM Drafts WHERE draftAccountId = :accountId")
void deleteAllDrafts(int accountId);
}

View File

@ -0,0 +1,47 @@
package org.mian.gitnex.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import org.mian.gitnex.database.models.Repository;
import java.util.List;
/**
* Author M M Arif
*/
@Dao
public interface RepositoriesDao {
@Insert
long newRepository(Repository repositories);
@Query("SELECT * FROM Repositories ORDER BY repositoryId ASC")
LiveData<List<Repository>> fetchAllRepositories();
@Query("SELECT * FROM Repositories WHERE repoAccountId = :repoAccountId")
LiveData<List<Repository>> getAllRepositoriesByAccountDao(int repoAccountId);
@Query("SELECT count(repositoryId) FROM Repositories WHERE repoAccountId = :repoAccountId AND repositoryOwner = :repositoryOwner AND repositoryName = :repositoryName")
Integer checkRepositoryDao(int repoAccountId, String repositoryOwner, String repositoryName);
@Query("SELECT * FROM Repositories WHERE repoAccountId = :repoAccountId AND repositoryOwner = :repositoryOwner AND repositoryName = :repositoryName")
Repository getSingleRepositoryDao(int repoAccountId, String repositoryOwner, String repositoryName);
@Query("SELECT * FROM Repositories WHERE repositoryId = :repositoryId")
Repository fetchRepositoryByIdDao(int repositoryId);
@Query("SELECT * FROM Repositories WHERE repositoryId = :repositoryId AND repoAccountId = :repoAccountId")
Repository fetchRepositoryByAccountIdByRepositoryIdDao(int repositoryId, int repoAccountId);
@Query("UPDATE Repositories SET repositoryOwner = :repositoryOwner, repositoryName = :repositoryName WHERE repositoryId = :repositoryId")
void updateRepositoryOwnerAndName(String repositoryOwner, String repositoryName, int repositoryId);
@Query("DELETE FROM Repositories WHERE repositoryId = :repositoryId")
void deleteRepository(int repositoryId);
@Query("DELETE FROM Repositories WHERE repoAccountId = :repoAccountId")
void deleteRepositoriesByAccount(int repoAccountId);
}

View File

@ -0,0 +1,56 @@
package org.mian.gitnex.database.dao;
import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import org.mian.gitnex.database.models.UserAccount;
import java.util.List;
/**
* Author M M Arif
*/
@Dao
public interface UserAccountsDao {
@Insert
long newAccount(UserAccount userAccounts);
@Query("SELECT * FROM UserAccounts ORDER BY accountId ASC")
LiveData<List<UserAccount>> fetchAllAccounts();
@Query("SELECT COUNT(accountId) FROM UserAccounts WHERE accountName = :accountName")
Integer getCount(String accountName);
@Query("SELECT * FROM UserAccounts WHERE accountName = :accountName")
UserAccount fetchRowByAccount_(String accountName);
@Query("SELECT * FROM UserAccounts WHERE accountId = :accountId")
UserAccount fetchRowByAccountId(int accountId);
@Query("UPDATE UserAccounts SET serverVersion = :serverVersion WHERE accountId = :accountId")
void updateServerVersion(String serverVersion, int accountId);
@Query("UPDATE UserAccounts SET accountName = :accountName WHERE accountId = :accountId")
void updateAccountName(String accountName, int accountId);
@Query("UPDATE UserAccounts SET token = :token WHERE accountId = :accountId")
void updateAccountToken(int accountId, String token);
@Query("UPDATE UserAccounts SET token = :token WHERE accountName = :accountName")
void updateAccountTokenByAccountName(String accountName, String token);
@Query("UPDATE UserAccounts SET instanceUrl = :instanceUrl, token = :token WHERE accountId = :accountId")
void updateHostInfo(String instanceUrl, String token, int accountId);
@Query("UPDATE UserAccounts SET userName = :userName WHERE accountId = :accountId")
void updateUserName(String userName, int accountId);
@Query("UPDATE UserAccounts SET instanceUrl = :instanceUrl, token = :token, userName = :userName, serverVersion = :serverVersion WHERE accountId = :accountId")
void updateAll(String instanceUrl, String token, String userName, String serverVersion, int accountId);
@Query("DELETE FROM UserAccounts WHERE accountId = :accountId")
void deleteAccount(int accountId);
}

View File

@ -0,0 +1,55 @@
package org.mian.gitnex.database.db;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.room.Database;
import androidx.room.Room;
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.RepositoriesDao;
import org.mian.gitnex.database.dao.UserAccountsDao;
import org.mian.gitnex.database.models.Draft;
import org.mian.gitnex.database.models.Repository;
import org.mian.gitnex.database.models.UserAccount;
/**
* Author M M Arif
*/
@Database(entities = {Draft.class, Repository.class, UserAccount.class},
version = 2, exportSchema = false)
public abstract class GitnexDatabase extends RoomDatabase {
private static GitnexDatabase gitnexDatabase;
public static GitnexDatabase getDatabaseInstance(Context context) {
if (gitnexDatabase == null) {
String DB_NAME = "gitnex";
gitnexDatabase = Room.databaseBuilder(context, GitnexDatabase.class, DB_NAME)
//.fallbackToDestructiveMigration()
.addMigrations(MIGRATION_1_2)
.build();
}
return gitnexDatabase;
}
public abstract DraftsDao draftsDao();
public abstract RepositoriesDao repositoriesDao();
public abstract UserAccountsDao userAccountsDao();
private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
//database.execSQL("DROP TABLE Drafts");
database.execSQL("ALTER TABLE 'Drafts' ADD COLUMN 'commentId' TEXT");
}
};
}

View File

@ -0,0 +1,102 @@
package org.mian.gitnex.database.models;
import androidx.annotation.Nullable;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import java.io.Serializable;
import static androidx.room.ForeignKey.CASCADE;
/**
* Author M M Arif
*/
@Entity(tableName = "Drafts", foreignKeys = @ForeignKey(entity = Repository.class, parentColumns = "repositoryId", childColumns = "draftRepositoryId", onDelete = CASCADE), indices = {@Index("draftRepositoryId")})
public class Draft implements Serializable {
@PrimaryKey(autoGenerate = true)
private int draftId;
private int draftRepositoryId;
private int draftAccountId;
private int issueId;
private String draftText;
@Nullable
private String draftType;
@Nullable
private String commentId;
public int getDraftId() {
return draftId;
}
public void setDraftId(int draftId) {
this.draftId = draftId;
}
public int getDraftRepositoryId() {
return draftRepositoryId;
}
public void setDraftRepositoryId(int draftRepositoryId) {
this.draftRepositoryId = draftRepositoryId;
}
public int getDraftAccountId() {
return draftAccountId;
}
public void setDraftAccountId(int draftAccountId) {
this.draftAccountId = draftAccountId;
}
public int getIssueId() {
return issueId;
}
public void setIssueId(int issueId) {
this.issueId = issueId;
}
public String getDraftText() {
return draftText;
}
public void setDraftText(String draftText) {
this.draftText = draftText;
}
@Nullable
public String getDraftType() {
return draftType;
}
public void setDraftType(@Nullable String draftType) {
this.draftType = draftType;
}
@Nullable
public String getCommentId() {
return commentId;
}
public void setCommentId(@Nullable String commentId) {
this.commentId = commentId;
}
}

View File

@ -0,0 +1,133 @@
package org.mian.gitnex.database.models;
/**
* Author M M Arif
*/
public class DraftWithRepository {
private int repositoryId;
private int draftId;
private int repoAccountId;
private String repositoryOwner;
private String repositoryName;
private int draftRepositoryId;
private int draftAccountId;
private int issueId;
private String draftText;
private String draftType;
private String commentId;
public int getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(int repositoryId) {
this.repositoryId = repositoryId;
}
public int getDraftId() {
return draftId;
}
public void setDraftId(int draftId) {
this.draftId = draftId;
}
public int getRepoAccountId() {
return repoAccountId;
}
public void setRepoAccountId(int repoAccountId) {
this.repoAccountId = repoAccountId;
}
public String getRepositoryOwner() {
return repositoryOwner;
}
public void setRepositoryOwner(String repositoryOwner) {
this.repositoryOwner = repositoryOwner;
}
public String getRepositoryName() {
return repositoryName;
}
public void setRepositoryName(String repositoryName) {
this.repositoryName = repositoryName;
}
public int getDraftRepositoryId() {
return draftRepositoryId;
}
public void setDraftRepositoryId(int draftRepositoryId) {
this.draftRepositoryId = draftRepositoryId;
}
public int getDraftAccountId() {
return draftAccountId;
}
public void setDraftAccountId(int draftAccountId) {
this.draftAccountId = draftAccountId;
}
public int getIssueId() {
return issueId;
}
public void setIssueId(int issueId) {
this.issueId = issueId;
}
public String getDraftText() {
return draftText;
}
public void setDraftText(String draftText) {
this.draftText = draftText;
}
public String getDraftType() {
return draftType;
}
public void setDraftType(String draftType) {
this.draftType = draftType;
}
public String getCommentId() {
return commentId;
}
public void setCommentId(String commentId) {
this.commentId = commentId;
}
}

View File

@ -0,0 +1,59 @@
package org.mian.gitnex.database.models;
import androidx.room.Entity;
import androidx.room.ForeignKey;
import androidx.room.Index;
import androidx.room.PrimaryKey;
import java.io.Serializable;
import static androidx.room.ForeignKey.CASCADE;
/**
* Author M M Arif
*/
@Entity(tableName = "Repositories", foreignKeys = @ForeignKey(entity = UserAccount.class,
parentColumns = "accountId",
childColumns = "repoAccountId",
onDelete = CASCADE),
indices = {@Index("repoAccountId")})
public class Repository implements Serializable {
@PrimaryKey(autoGenerate = true)
private int repositoryId;
private int repoAccountId;
private String repositoryOwner;
private String repositoryName;
public int getRepositoryId() {
return repositoryId;
}
public void setRepositoryId(int repositoryId) {
this.repositoryId = repositoryId;
}
public int getRepoAccountId() {
return repoAccountId;
}
public void setRepoAccountId(int repoAccountId) {
this.repoAccountId = repoAccountId;
}
public String getRepositoryOwner() {
return repositoryOwner;
}
public void setRepositoryOwner(String repositoryOwner) {
this.repositoryOwner = repositoryOwner;
}
public String getRepositoryName() {
return repositoryName;
}
public void setRepositoryName(String repositoryName) {
this.repositoryName = repositoryName;
}
}

View File

@ -0,0 +1,75 @@
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 = "userAccounts")
public class UserAccount implements Serializable {
@PrimaryKey(autoGenerate = true)
private int accountId;
@Nullable
private String accountName;
private String instanceUrl;
private String userName;
private String token;
@Nullable
private String serverVersion;
public int getAccountId() {
return accountId;
}
public void setAccountId(int accountId) {
this.accountId = accountId;
}
@Nullable
public String getAccountName() {
return accountName;
}
public void setAccountName(@Nullable String accountName) {
this.accountName = accountName;
}
public String getInstanceUrl() {
return instanceUrl;
}
public void setInstanceUrl(String instanceUrl) {
this.instanceUrl = instanceUrl;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
@Nullable
public String getServerVersion() {
return serverVersion;
}
public void setServerVersion(@Nullable String serverVersion) {
this.serverVersion = serverVersion;
}
}

View File

@ -3,19 +3,16 @@ package org.mian.gitnex.fragments;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.CreditsActivity;
import org.mian.gitnex.activities.MainActivity;
import org.mian.gitnex.activities.SponsorsActivity;
import org.mian.gitnex.util.AppUtil;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.helpers.AppUtil;
import org.mian.gitnex.helpers.TinyDB;
import java.util.Objects;
/**
@ -34,83 +31,62 @@ public class AboutFragment extends Fragment {
final TextView donationLink;
final TextView donationLinkPatreon;
final TextView translateLink;
final TextView creditsButton;
final TextView sponsorsButton;
final TextView appWebsite;
final TextView appRepo;
appVerBuild = v.findViewById(R.id.appVerBuild);
TextView viewTextGiteaVersion = v.findViewById(R.id.giteaVersion);
creditsButton = v.findViewById(R.id.creditsButton);
donationLink = v.findViewById(R.id.donationLink);
donationLinkPatreon = v.findViewById(R.id.donationLinkPatreon);
translateLink = v.findViewById(R.id.translateLink);
sponsorsButton = v.findViewById(R.id.sponsorsButton);
appWebsite = v.findViewById(R.id.appWebsite);
appRepo = v.findViewById(R.id.appRepo);
appVerBuild.setText(getString(R.string.appVerBuild, AppUtil.getAppVersion(Objects.requireNonNull(getContext())), AppUtil.getAppBuildNo(getContext())));
donationLink.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.supportLink)));
startActivity(intent);
}
donationLink.setOnClickListener(v1 -> {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.supportLink)));
startActivity(intent);
});
donationLinkPatreon.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.supportLinkPatreon)));
startActivity(intent);
}
donationLinkPatreon.setOnClickListener(v12 -> {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.supportLinkPatreon)));
startActivity(intent);
});
translateLink.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.crowdInLink)));
startActivity(intent);
}
translateLink.setOnClickListener(v13 -> {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.crowdInLink)));
startActivity(intent);
});
appWebsite.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.appWebsiteLink)));
startActivity(intent);
}
appWebsite.setOnClickListener(v14 -> {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.appWebsiteLink)));
startActivity(intent);
});
appRepo.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.appRepoLink)));
startActivity(intent);
}
});
appRepo.setOnClickListener(v15 -> {
creditsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(getContext(), CreditsActivity.class));
}
});
sponsorsButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(getContext(), SponsorsActivity.class));
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.addCategory(Intent.CATEGORY_BROWSABLE);
intent.setData(Uri.parse(getResources().getString(R.string.appRepoLink)));
startActivity(intent);
});
String commit = getResources().getString(R.string.commitPage) + tinyDb.getString("giteaVersion");

View File

@ -11,7 +11,7 @@ import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import org.mian.gitnex.R;
import org.mian.gitnex.activities.AdminGetUsersActivity;
import org.mian.gitnex.util.TinyDB;
import org.mian.gitnex.helpers.TinyDB;
/**
* Author M M Arif

View File

@ -26,12 +26,10 @@ public class BottomSheetAdminUsersFragment extends BottomSheetDialogFragment {
TextView createNewUser = v.findViewById(R.id.createNewUser);
createNewUser.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bmListener.onButtonClicked("newUser");
dismiss();
}
createNewUser.setOnClickListener(v1 -> {
bmListener.onButtonClicked("newUser");
dismiss();
});
return v;
@ -47,9 +45,9 @@ public class BottomSheetAdminUsersFragment extends BottomSheetDialogFragment {
try {
bmListener = (BottomSheetAdminUsersFragment.BottomSheetListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString()
+ " must implement BottomSheetListener");
}
catch (ClassCastException e) {
throw new ClassCastException(context.toString() + " must implement BottomSheetListener");
}
}

View File

@ -0,0 +1,58 @@
package org.mian.gitnex.fragments;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import org.mian.gitnex.R;
import org.mian.gitnex.helpers.StaticGlobalVariables;
/**
* Author M M Arif
*/
public class BottomSheetDraftsFragment extends BottomSheetDialogFragment {
private String TAG = StaticGlobalVariables.tagDraftsBottomSheet;
private BottomSheetDraftsFragment.BottomSheetListener bmListener;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bottom_sheet_drafts, container, false);
TextView deleteAllDrafts = v.findViewById(R.id.deleteAllDrafts);
deleteAllDrafts.setOnClickListener(v1 -> {
dismiss();
bmListener.onButtonClicked("deleteDrafts");
});
return v;
}
public interface BottomSheetListener {
void onButtonClicked(String text);
}
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
bmListener = (BottomSheetDraftsFragment.BottomSheetListener) context;
}
catch (ClassCastException e) {
Log.e(TAG, e.toString());
}
}
}

Some files were not shown because too many files have changed in this diff Show More