Merge branch 'master' into 7-assign-team-to-repo
This commit is contained in:
@ -6,8 +6,8 @@ android {
|
||||
applicationId "org.mian.gitnex"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
versionCode 327
|
||||
versionName "3.3.0-dev"
|
||||
versionCode 346
|
||||
versionName "3.5.0-dev"
|
||||
multiDexEnabled true
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@ -38,8 +38,10 @@ android {
|
||||
abortOnError false
|
||||
}
|
||||
compileOptions {
|
||||
targetCompatibility = "8"
|
||||
sourceCompatibility = "8"
|
||||
coreLibraryDesugaringEnabled true
|
||||
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
defaultConfig{
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
@ -52,18 +54,18 @@ configurations {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
def lifecycle_version = '2.3.0-beta01'
|
||||
def markwon_version = '4.6.0'
|
||||
def lifecycle_version = '2.3.0-rc01'
|
||||
def markwon_version = '4.6.1'
|
||||
def work_version = "2.4.0"
|
||||
def acra = "5.5.0"
|
||||
def acra = "5.7.0"
|
||||
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
|
||||
implementation 'com.google.android.material:material:1.3.0-alpha03'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
|
||||
implementation "androidx.legacy:legacy-support-v4:1.0.0"
|
||||
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
|
||||
testImplementation "junit:junit:4.13"
|
||||
testImplementation 'junit:junit:4.13.1'
|
||||
androidTestImplementation 'androidx.test:runner:1.3.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.9.0'
|
||||
@ -74,8 +76,7 @@ dependencies {
|
||||
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.9.0'
|
||||
implementation 'org.ocpsoft.prettytime:prettytime:4.0.6.Final'
|
||||
implementation "com.vdurmont:emoji-java:5.1.1"
|
||||
implementation 'org.ocpsoft.prettytime:prettytime:5.0.0.Final'
|
||||
implementation "com.pes.materialcolorpicker:library:1.2.5"
|
||||
implementation "io.noties.markwon:core:$markwon_version"
|
||||
implementation "io.noties.markwon:ext-latex:$markwon_version"
|
||||
@ -90,10 +91,11 @@ dependencies {
|
||||
implementation "io.noties.markwon:recycler-table:$markwon_version"
|
||||
implementation "io.noties.markwon:simple-ext:$markwon_version"
|
||||
implementation "io.noties.markwon:syntax-highlight:$markwon_version"
|
||||
implementation "io.noties.markwon:image-picasso:$markwon_version"
|
||||
implementation "io.noties:prism4j:2.0.0"
|
||||
annotationProcessor "io.noties:prism4j-bundler:2.0.0"
|
||||
implementation "com.caverock:androidsvg:1.4"
|
||||
implementation "pl.droidsonroids.gif:android-gif-drawable:1.2.19"
|
||||
implementation "com.hendraanggrian.appcompat:socialview:0.2"
|
||||
implementation "com.hendraanggrian.appcompat:socialview-commons:0.2"
|
||||
implementation "pl.droidsonroids.gif:android-gif-drawable:1.2.21"
|
||||
implementation "com.github.HamidrezaAmz:BreadcrumbsView:0.2.9"
|
||||
implementation "commons-io:commons-io:20030203.000550"
|
||||
implementation 'org.apache.commons:commons-lang3:3.11'
|
||||
@ -102,10 +104,12 @@ dependencies {
|
||||
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.room:room-runtime:2.2.6'
|
||||
annotationProcessor 'androidx.room:room-compiler:2.2.6'
|
||||
implementation "androidx.work:work-runtime:$work_version"
|
||||
implementation "com.eightbitlab:blurview:1.6.3"
|
||||
implementation "com.eightbitlab:blurview:1.6.4"
|
||||
implementation "io.mikael:urlbuilder:2.0.9"
|
||||
implementation "org.codeberg.gitnex-garage:emoji-java:v5.1.2"
|
||||
coreLibraryDesugaring "com.android.tools:desugar_jdk_libs:1.1.1"
|
||||
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@ -74,9 +75,6 @@
|
||||
<activity
|
||||
android:name=".activities.CreateMilestoneActivity"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||
<activity
|
||||
android:name=".activities.ReplyToIssueActivity"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||
<activity
|
||||
android:name=".activities.IssueDetailActivity"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation"
|
||||
@ -153,12 +151,42 @@
|
||||
<activity
|
||||
android:name=".activities.CreatePullRequestActivity"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||
<activity
|
||||
android:name=".activities.SettingsGeneralActivity"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||
<activity
|
||||
android:name=".activities.SettingsNotificationsActivity"
|
||||
android:configChanges="orientation|screenSize|smallestScreenSize|density|screenLayout|uiMode|keyboard|keyboardHidden|navigation" />
|
||||
|
||||
<!-- 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"/>
|
||||
|
||||
<!-- deep links -->
|
||||
<activity
|
||||
android:name=".activities.DeepLinksActivity"
|
||||
android:theme="@android:style/Theme.Translucent.NoTitleBar"
|
||||
android:noHistory="true"
|
||||
android:launchMode="singleTask">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="http" />
|
||||
<data android:scheme="https" />
|
||||
<data android:host="codeberg.org" />
|
||||
<data android:host="gitea.com" />
|
||||
<data android:host="try.gitea.io" />
|
||||
<data android:host="code.obermui.de" />
|
||||
<data android:host="git.fsfe.org" />
|
||||
<data android:host="opendev.org" />
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
<!-- deep links -->
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 3.2 KiB |
@ -24,12 +24,11 @@ import retrofit2.Callback;
|
||||
|
||||
public class AssigneesActions {
|
||||
|
||||
public static void getCurrentIssueAssignees(Context ctx, String instanceUrl, String loginUid, String instanceToken, String repoOwner, String repoName, int issueIndex, List<String> currentAssignees) {
|
||||
public static void getCurrentIssueAssignees(Context ctx, String repoOwner, String repoName, int issueIndex, List<String> currentAssignees) {
|
||||
|
||||
Call<Issues> callSingleIssueLabels = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
||||
.getApiInterface(ctx)
|
||||
.getIssueByIndex(Authorization.get(ctx), repoOwner, repoName, issueIndex);
|
||||
|
||||
callSingleIssueLabels.enqueue(new Callback<Issues>() {
|
||||
|
||||
@ -63,14 +62,13 @@ public class AssigneesActions {
|
||||
});
|
||||
}
|
||||
|
||||
public static void getRepositoryAssignees(Context ctx, String instanceUrl, String instanceToken, String repoOwner, String repoName, List<Collaborators> assigneesList, Dialog dialogAssignees, AssigneesListAdapter assigneesAdapter, CustomAssigneesSelectionDialogBinding assigneesBinding) {
|
||||
public static void getRepositoryAssignees(Context ctx, String repoOwner, String repoName, List<Collaborators> assigneesList, Dialog dialogAssignees, AssigneesListAdapter assigneesAdapter, CustomAssigneesSelectionDialogBinding assigneesBinding) {
|
||||
|
||||
TinyDB tinyDB = new TinyDB(ctx);
|
||||
TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||
|
||||
Call<List<Collaborators>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getCollaborators(instanceToken, repoOwner, repoName);
|
||||
.getApiInterface(ctx)
|
||||
.getCollaborators(Authorization.get(ctx), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<List<Collaborators>>() {
|
||||
|
||||
@ -89,8 +87,6 @@ public class AssigneesActions {
|
||||
|
||||
if(assigneesList_.size() > 0) {
|
||||
|
||||
dialogAssignees.show();
|
||||
|
||||
assigneesList.add(new Collaborators(tinyDB.getString("userFullname"), tinyDB.getString("loginUid"), tinyDB.getString("userAvatar")));
|
||||
assigneesList.addAll(assigneesList_);
|
||||
}
|
||||
|
@ -25,21 +25,16 @@ public class CollaboratorActions {
|
||||
|
||||
public static void deleteCollaborator(final Context context, final String searchKeyword, String userName) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
|
||||
Call<Collaborators> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.deleteCollaborator(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName, userName);
|
||||
Call<Collaborators> call = RetrofitClient
|
||||
.getApiInterface(context)
|
||||
.deleteCollaborator(Authorization.get(context), repoOwner, repoName, userName);
|
||||
|
||||
call.enqueue(new Callback<Collaborators>() {
|
||||
|
||||
@ -54,7 +49,7 @@ public class CollaboratorActions {
|
||||
//Log.i("addCollaboratorSearch", addCollaboratorSearch.getText().toString());
|
||||
//tinyDb.putBoolean("updateDataSet", true);
|
||||
//AddCollaboratorToRepositoryActivity usersSearchData = new AddCollaboratorToRepositoryActivity();
|
||||
//usersSearchData.loadUserSearchList(instanceUrl, instanceToken, searchKeyword, context);
|
||||
//usersSearchData.loadUserSearchList(instanceToken, searchKeyword, context);
|
||||
|
||||
}
|
||||
}
|
||||
@ -94,22 +89,18 @@ public class CollaboratorActions {
|
||||
|
||||
public static void addCollaborator(final Context context, String permission, String userName) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
|
||||
Permission permissionString = new Permission(permission);
|
||||
Call<Permission> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.addCollaborator(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName, userName, permissionString);
|
||||
Call<Permission> call = RetrofitClient
|
||||
.getApiInterface(context)
|
||||
.addCollaborator(Authorization.get(context), repoOwner, repoName, userName, permissionString);
|
||||
|
||||
call.enqueue(new Callback<Permission>() {
|
||||
|
||||
@ -122,7 +113,7 @@ public class CollaboratorActions {
|
||||
Toasty.success(context, context.getString(R.string.addCollaboratorToastText));
|
||||
((AddCollaboratorToRepositoryActivity)context).finish();
|
||||
//AddCollaboratorToRepositoryActivity usersSearchData = new AddCollaboratorToRepositoryActivity();
|
||||
//usersSearchData.loadUserSearchList(instanceUrl, instanceToken, searchKeyword, context);
|
||||
//usersSearchData.loadUserSearchList(instanceToken, searchKeyword, context);
|
||||
|
||||
}
|
||||
}
|
||||
@ -164,11 +155,7 @@ public class CollaboratorActions {
|
||||
public static ActionResult<List<Collaborators>> getCollaborators(Context context) {
|
||||
|
||||
ActionResult<List<Collaborators>> actionResult = new ActionResult<>();
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
|
||||
String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
String loginUid = tinyDb.getString("loginUid");
|
||||
String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
@ -176,9 +163,8 @@ public class CollaboratorActions {
|
||||
String repoName = parts[1];
|
||||
|
||||
Call<List<Collaborators>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.getCollaborators(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
||||
.getApiInterface(context)
|
||||
.getCollaborators(Authorization.get(context), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<List<Collaborators>>() {
|
||||
|
||||
|
@ -5,7 +5,6 @@ import androidx.annotation.NonNull;
|
||||
import com.google.gson.JsonElement;
|
||||
import org.mian.gitnex.R;
|
||||
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;
|
||||
@ -15,6 +14,7 @@ import org.mian.gitnex.models.Issues;
|
||||
import org.mian.gitnex.models.UpdateIssueState;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -22,85 +22,72 @@ import retrofit2.Callback;
|
||||
|
||||
public class IssueActions {
|
||||
|
||||
public static void editIssueComment(final Context ctx, final int commentId, final String commentBody, long draftIdOnCreate) {
|
||||
public static ActionResult<Response<?>> edit(Context context, String comment, int commentId) {
|
||||
|
||||
ActionResult<Response<?>> actionResult = new ActionResult<>();
|
||||
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(ctx);
|
||||
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];
|
||||
|
||||
IssueComments commentBodyJson = new IssueComments(commentBody);
|
||||
Call<IssueComments> call;
|
||||
String repoOwner = parts[0];
|
||||
String repoName = parts[1];
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().patchIssueComment(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, commentId, commentBodyJson);
|
||||
Call<IssueComments> call = RetrofitClient
|
||||
.getApiInterface(context)
|
||||
.patchIssueComment(Authorization.get(context), repoOwner, repoName, commentId, new IssueComments(comment));
|
||||
|
||||
call.enqueue(new Callback<IssueComments>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<IssueComments> call, @NonNull retrofit2.Response<IssueComments> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
if(response.code() == 200) {
|
||||
switch(response.code()) {
|
||||
|
||||
tinyDb.putBoolean("commentEdited", true);
|
||||
Toasty.info(ctx, ctx.getString(R.string.editCommentUpdatedText));
|
||||
case 200:
|
||||
actionResult.finish(ActionResult.Status.SUCCESS);
|
||||
break;
|
||||
|
||||
DraftsApi draftsApi = new DraftsApi(ctx);
|
||||
draftsApi.deleteSingleDraft((int) draftIdOnCreate);
|
||||
case 401:
|
||||
actionResult.finish(ActionResult.Status.FAILED, response);
|
||||
AlertDialogs.authorizationTokenRevokedDialog(context, context.getResources().getString(R.string.alertDialogTokenRevokedTitle), context.getResources().getString(R.string.alertDialogTokenRevokedMessage), context.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), context.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, ctx.getResources().getString(R.string.alertDialogTokenRevokedTitle), ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage), ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton), ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
default:
|
||||
actionResult.finish(ActionResult.Status.FAILED, response);
|
||||
break;
|
||||
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
|
||||
}
|
||||
else if(response.code() == 404) {
|
||||
|
||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<IssueComments> call, @NonNull Throwable t) {
|
||||
|
||||
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
||||
actionResult.finish(ActionResult.Status.FAILED);
|
||||
}
|
||||
});
|
||||
|
||||
return actionResult;
|
||||
|
||||
}
|
||||
|
||||
public static void closeReopenIssue(final Context ctx, final int issueIndex, final String issueState) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(ctx);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(ctx);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
|
||||
UpdateIssueState issueStatJson = new UpdateIssueState(issueState);
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().closeReopenIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, issueStatJson);
|
||||
call = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.closeReopenIssue(Authorization.get(ctx), repoOwner, repoName, issueIndex, issueStatJson);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -162,20 +149,23 @@ public class IssueActions {
|
||||
|
||||
public static void subscribe(final Context ctx) {
|
||||
|
||||
final TinyDB tinyDB = new TinyDB(ctx);
|
||||
final TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||
|
||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
||||
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
||||
|
||||
if(repoFullName.length != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String userLogin = tinyDB.getString("userLogin");
|
||||
final String token = "token " + tinyDB.getString(tinyDB.getString("loginUid") + "-token");
|
||||
final int issueNr = Integer.parseInt(tinyDB.getString("issueNumber"));
|
||||
|
||||
Call<Void> call;
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().addIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
||||
call = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.addIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
||||
|
||||
call.enqueue(new Callback<Void>() {
|
||||
|
||||
@ -222,9 +212,8 @@ public class IssueActions {
|
||||
|
||||
public static void unsubscribe(final Context ctx) {
|
||||
|
||||
final TinyDB tinyDB = new TinyDB(ctx);
|
||||
final TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||
|
||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
||||
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
||||
if(repoFullName.length != 2) {
|
||||
return;
|
||||
@ -235,7 +224,7 @@ public class IssueActions {
|
||||
|
||||
Call<Void> call;
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().delIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
||||
call = RetrofitClient.getApiInterface(ctx).delIssueSubscriber(token, repoFullName[0], repoFullName[1], issueNr, userLogin);
|
||||
|
||||
call.enqueue(new Callback<Void>() {
|
||||
|
||||
@ -282,11 +271,8 @@ public class IssueActions {
|
||||
public static ActionResult<ActionResult.None> reply(Context context, String comment, int issueIndex) {
|
||||
|
||||
ActionResult<ActionResult.None> actionResult = new ActionResult<>();
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
|
||||
String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
String loginUid = tinyDb.getString("loginUid");
|
||||
String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
@ -296,9 +282,8 @@ public class IssueActions {
|
||||
Issues issueComment = new Issues(comment);
|
||||
|
||||
Call<Issues> call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.replyCommentToIssue(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName, issueIndex, issueComment);
|
||||
.getApiInterface(context)
|
||||
.replyCommentToIssue(Authorization.get(context), repoOwner, repoName, issueIndex, issueComment);
|
||||
|
||||
call.enqueue(new Callback<Issues>() {
|
||||
|
||||
|
@ -22,12 +22,11 @@ import retrofit2.Callback;
|
||||
|
||||
public class LabelsActions {
|
||||
|
||||
public static void getCurrentIssueLabels(Context ctx, String instanceUrl, String loginUid, String instanceToken, String repoOwner, String repoName, int issueIndex, List<Integer> currentLabelsIds) {
|
||||
public static void getCurrentIssueLabels(Context ctx, String repoOwner, String repoName, int issueIndex, List<Integer> currentLabelsIds) {
|
||||
|
||||
Call<List<Labels>> callSingleIssueLabels = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getIssueLabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
||||
.getApiInterface(ctx)
|
||||
.getIssueLabels(Authorization.get(ctx), repoOwner, repoName, issueIndex);
|
||||
|
||||
callSingleIssueLabels.enqueue(new Callback<List<Labels>>() {
|
||||
|
||||
@ -60,12 +59,11 @@ public class LabelsActions {
|
||||
});
|
||||
}
|
||||
|
||||
public static void getRepositoryLabels(Context ctx, String instanceUrl, String instanceToken, String repoOwner, String repoName, List<Labels> labelsList, Dialog dialogLabels, LabelsListAdapter labelsAdapter, CustomLabelsSelectionDialogBinding labelsBinding) {
|
||||
public static void getRepositoryLabels(Context ctx, String repoOwner, String repoName, List<Labels> labelsList, Dialog dialogLabels, LabelsListAdapter labelsAdapter, CustomLabelsSelectionDialogBinding labelsBinding) {
|
||||
|
||||
Call<List<Labels>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getlabels(instanceToken, repoOwner, repoName);
|
||||
.getApiInterface(ctx)
|
||||
.getLabels(Authorization.get(ctx), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<List<Labels>>() {
|
||||
|
||||
@ -73,28 +71,45 @@ public class LabelsActions {
|
||||
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> response) {
|
||||
|
||||
labelsList.clear();
|
||||
List<Labels> labelsList_ = response.body();
|
||||
|
||||
labelsBinding.progressBar.setVisibility(View.GONE);
|
||||
labelsBinding.dialogFrame.setVisibility(View.VISIBLE);
|
||||
|
||||
if (response.code() == 200) {
|
||||
|
||||
assert labelsList_ != null;
|
||||
if(response.body() != null) {
|
||||
|
||||
if(labelsList_.size() > 0) {
|
||||
|
||||
dialogLabels.show();
|
||||
|
||||
labelsList.addAll(labelsList_);
|
||||
}
|
||||
else {
|
||||
|
||||
dialogLabels.dismiss();
|
||||
Toasty.warning(ctx, ctx.getResources().getString(R.string.noLabelsFound));
|
||||
labelsList.addAll(response.body());
|
||||
}
|
||||
|
||||
labelsBinding.labelsRecyclerView.setAdapter(labelsAdapter);
|
||||
// Load organization labels
|
||||
Call<List<Labels>> callOrgLabels = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.getOrganizationLabels(Authorization.get(ctx), repoOwner);
|
||||
|
||||
callOrgLabels.enqueue(new Callback<List<Labels>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Labels>> call, @NonNull retrofit2.Response<List<Labels>> responseOrg) {
|
||||
|
||||
labelsBinding.progressBar.setVisibility(View.GONE);
|
||||
labelsBinding.dialogFrame.setVisibility(View.VISIBLE);
|
||||
|
||||
if(responseOrg.body() != null) {
|
||||
|
||||
labelsList.addAll(responseOrg.body());
|
||||
}
|
||||
|
||||
if(labelsList.isEmpty()) {
|
||||
|
||||
dialogLabels.dismiss();
|
||||
Toasty.warning(ctx, ctx.getResources().getString(R.string.noLabelsFound));
|
||||
|
||||
}
|
||||
|
||||
labelsBinding.labelsRecyclerView.setAdapter(labelsAdapter);
|
||||
}
|
||||
|
||||
@Override public void onFailure(@NonNull Call<List<Labels>> call, @NonNull Throwable t) {}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
else {
|
||||
|
@ -23,9 +23,8 @@ public class MilestoneActions {
|
||||
|
||||
public static void closeMilestone(final Context ctx, int milestoneId_) {
|
||||
|
||||
final TinyDB tinyDB = new TinyDB(ctx);
|
||||
final TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||
|
||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
@ -37,8 +36,7 @@ public class MilestoneActions {
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.closeReopenMilestone(token, repoOwner, repoName, milestoneId_, milestoneStateJson);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
@ -81,9 +79,8 @@ public class MilestoneActions {
|
||||
|
||||
public static void openMilestone(final Context ctx, int milestoneId_) {
|
||||
|
||||
final TinyDB tinyDB = new TinyDB(ctx);
|
||||
final TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||
|
||||
final String instanceUrl = tinyDB.getString("instanceUrl");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
@ -95,8 +92,7 @@ public class MilestoneActions {
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.closeReopenMilestone(token, repoOwner, repoName, milestoneId_, milestoneStateJson);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
@ -20,24 +20,22 @@ public class NotificationsActions {
|
||||
|
||||
private TinyDB tinyDB;
|
||||
private Context context;
|
||||
private String instanceUrl;
|
||||
private String instanceToken;
|
||||
|
||||
public NotificationsActions(Context context) {
|
||||
|
||||
this.context = context;
|
||||
this.tinyDB = new TinyDB(context);
|
||||
this.tinyDB = TinyDB.getInstance(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()
|
||||
Call<ResponseBody> call = RetrofitClient.getApiInterface(context)
|
||||
.markNotificationThreadAsRead(instanceToken, notificationThread.getId(), notificationStatus.name());
|
||||
|
||||
if(!call.execute().isSuccessful()) {
|
||||
@ -48,7 +46,7 @@ public class NotificationsActions {
|
||||
|
||||
public boolean setAllNotificationsRead(Date date) throws IOException {
|
||||
|
||||
Call<ResponseBody> call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface()
|
||||
Call<ResponseBody> call = RetrofitClient.getApiInterface(context)
|
||||
.markNotificationThreadsAsRead(instanceToken, AppUtil.getTimestampFromDate(context, date), true,
|
||||
new String[]{"unread", "pinned"}, "read");
|
||||
|
||||
|
@ -21,10 +21,8 @@ public class RepositoryActions {
|
||||
|
||||
public static void starRepository(final Context context) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
@ -33,9 +31,8 @@ public class RepositoryActions {
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.starRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
||||
.getApiInterface(context)
|
||||
.starRepository(Authorization.get(context), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -86,10 +83,8 @@ public class RepositoryActions {
|
||||
|
||||
public static void unStarRepository(final Context context) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
@ -98,9 +93,8 @@ public class RepositoryActions {
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.unStarRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
||||
.getApiInterface(context)
|
||||
.unStarRepository(Authorization.get(context), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -151,10 +145,8 @@ public class RepositoryActions {
|
||||
|
||||
public static void watchRepository(final Context context) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
@ -163,9 +155,8 @@ public class RepositoryActions {
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.watchRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
||||
.getApiInterface(context)
|
||||
.watchRepository(Authorization.get(context), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -216,10 +207,8 @@ public class RepositoryActions {
|
||||
|
||||
public static void unWatchRepository(final Context context) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
@ -228,9 +217,8 @@ public class RepositoryActions {
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.unWatchRepository(Authorization.returnAuthentication(context, loginUid, instanceToken), repoOwner, repoName);
|
||||
.getApiInterface(context)
|
||||
.unWatchRepository(Authorization.get(context), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
|
@ -21,17 +21,13 @@ public class TeamActions {
|
||||
|
||||
public static void removeTeamMember(final Context context, String userName, int teamId) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.removeTeamMember(Authorization.returnAuthentication(context, loginUid, instanceToken), teamId, userName);
|
||||
.getApiInterface(context)
|
||||
.removeTeamMember(Authorization.get(context), teamId, userName);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -87,17 +83,11 @@ public class TeamActions {
|
||||
|
||||
public static void addTeamMember(final Context context, String userName, int teamId) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, context)
|
||||
.getApiInterface()
|
||||
.addTeamMember(Authorization.returnAuthentication(context, loginUid, instanceToken), teamId, userName);
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getApiInterface(context)
|
||||
.addTeamMember(Authorization.get(context), teamId, userName);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
|
@ -17,7 +17,6 @@ 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.helpers.TinyDB;
|
||||
import org.mian.gitnex.models.UserInfo;
|
||||
import org.mian.gitnex.models.UserSearch;
|
||||
import java.util.List;
|
||||
@ -32,8 +31,6 @@ import retrofit2.Response;
|
||||
public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private TextView addCollaboratorSearch;
|
||||
private TextView noData;
|
||||
private ProgressBar mProgressBar;
|
||||
@ -49,21 +46,13 @@ public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
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");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
addCollaboratorSearch = findViewById(R.id.addCollaboratorSearch);
|
||||
mRecyclerView = findViewById(R.id.recyclerViewUserSearch);
|
||||
mProgressBar = findViewById(R.id.progress_bar);
|
||||
mProgressBar = findViewById(R.id.progressBar);
|
||||
noData = findViewById(R.id.noData);
|
||||
|
||||
addCollaboratorSearch.requestFocus();
|
||||
@ -76,8 +65,11 @@ public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
||||
addCollaboratorSearch.setOnEditorActionListener((v, actionId, event) -> {
|
||||
|
||||
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||
|
||||
if(!addCollaboratorSearch.getText().toString().equals("")) {
|
||||
loadUserSearchList(instanceUrl, instanceToken, addCollaboratorSearch.getText().toString(), loginUid);
|
||||
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
loadUserSearchList(addCollaboratorSearch.getText().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -87,22 +79,26 @@ public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
public void loadUserSearchList(String instanceUrl, String token, String searchKeyword, String loginUid) {
|
||||
public void loadUserSearchList(String searchKeyword) {
|
||||
|
||||
Call<UserSearch> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getUserBySearch(Authorization.returnAuthentication(ctx, loginUid, token), searchKeyword, 10);
|
||||
.getApiInterface(appCtx)
|
||||
.getUserBySearch(Authorization.get(ctx), searchKeyword, 10);
|
||||
|
||||
call.enqueue(new Callback<UserSearch>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<UserSearch> call, @NonNull Response<UserSearch> response) {
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
if (response.code() == 200) {
|
||||
|
||||
assert response.body() != null;
|
||||
getUsersList(response.body().getData(), ctx);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
@ -129,15 +125,16 @@ public class AddCollaboratorToRepositoryActivity extends BaseActivity {
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
if(adapter.getItemCount() > 0) {
|
||||
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
@ -15,7 +14,6 @@ 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;
|
||||
@ -32,10 +30,6 @@ import retrofit2.Callback;
|
||||
|
||||
public class AddNewAccountActivity extends BaseActivity {
|
||||
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private TinyDB tinyDB;
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
private ActivityAddNewAccountBinding viewBinding;
|
||||
|
||||
@ -52,8 +46,6 @@ public class AddNewAccountActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
tinyDB = new TinyDB(appCtx);
|
||||
|
||||
viewBinding = ActivityAddNewAccountBinding.inflate(getLayoutInflater());
|
||||
View view = viewBinding.getRoot();
|
||||
@ -76,7 +68,6 @@ public class AddNewAccountActivity extends BaseActivity {
|
||||
if(!connToInternet) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@ -132,7 +123,7 @@ public class AddNewAccountActivity extends BaseActivity {
|
||||
|
||||
Call<GiteaVersion> callVersion;
|
||||
|
||||
callVersion = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithToken("token " + loginToken);
|
||||
callVersion = RetrofitClient.getApiInterface(ctx).getGiteaVersionWithToken("token " + loginToken);
|
||||
|
||||
callVersion.enqueue(new Callback<GiteaVersion>() {
|
||||
|
||||
@ -144,7 +135,9 @@ public class AddNewAccountActivity extends BaseActivity {
|
||||
GiteaVersion version = responseVersion.body();
|
||||
|
||||
assert version != null;
|
||||
|
||||
if(!Version.valid(version.getVersion())) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
|
||||
return;
|
||||
}
|
||||
@ -170,7 +163,6 @@ public class AddNewAccountActivity extends BaseActivity {
|
||||
});
|
||||
|
||||
alertDialogBuilder.create().show();
|
||||
|
||||
}
|
||||
else if(giteaVersion.lessOrEqual(getString(R.string.versionHigh))) {
|
||||
|
||||
@ -180,7 +172,6 @@ public class AddNewAccountActivity extends BaseActivity {
|
||||
|
||||
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
|
||||
login(instanceUrl, loginToken);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -193,7 +184,6 @@ public class AddNewAccountActivity extends BaseActivity {
|
||||
private void login(String instanceUrl, String loginToken) {
|
||||
|
||||
setupNewAccountWithToken(instanceUrl, loginToken);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -207,7 +197,7 @@ public class AddNewAccountActivity extends BaseActivity {
|
||||
|
||||
private void setupNewAccountWithToken(String instanceUrl, final String loginToken) {
|
||||
|
||||
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserInfo("token " + loginToken);
|
||||
Call<UserInfo> call = RetrofitClient.getApiInterface(ctx, instanceUrl).getUserInfo("token " + loginToken);
|
||||
|
||||
call.enqueue(new Callback<UserInfo>() {
|
||||
|
||||
|
@ -18,7 +18,6 @@ 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 java.util.ArrayList;
|
||||
@ -35,8 +34,6 @@ import retrofit2.Response;
|
||||
public class AddNewTeamMemberActivity extends BaseActivity {
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private TextView addNewTeamMember;
|
||||
private TextView noData;
|
||||
private ProgressBar mProgressBar;
|
||||
@ -56,17 +53,9 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
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");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
addNewTeamMember = findViewById(R.id.addNewTeamMember);
|
||||
mRecyclerView = findViewById(R.id.recyclerViewUserSearch);
|
||||
@ -81,9 +70,11 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
if(getIntent().getStringExtra("teamId") != null && !Objects.requireNonNull(getIntent().getStringExtra("teamId")).equals("")) {
|
||||
|
||||
teamId = getIntent().getStringExtra("teamId");
|
||||
}
|
||||
else {
|
||||
|
||||
teamId = "0";
|
||||
}
|
||||
|
||||
@ -103,10 +94,8 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
||||
if(!addNewTeamMember.getText().toString().equals("") && addNewTeamMember.getText().toString().length() > 1) {
|
||||
|
||||
adapter = new UserSearchForTeamMemberAdapter(dataList, ctx, Integer.parseInt(teamId));
|
||||
loadUserSearchList(instanceUrl, instanceToken, addNewTeamMember.getText().toString(), loginUid, teamId);
|
||||
|
||||
loadUserSearchList(addNewTeamMember.getText().toString(), teamId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -121,9 +110,9 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
public void loadUserSearchList(String instanceUrl, String token, String searchKeyword, String loginUid, String teamId) {
|
||||
public void loadUserSearchList(String searchKeyword, String teamId) {
|
||||
|
||||
Call<UserSearch> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserBySearch(Authorization.returnAuthentication(ctx, loginUid, token), searchKeyword, 10);
|
||||
Call<UserSearch> call = RetrofitClient.getApiInterface(ctx).getUserBySearch(Authorization.get(ctx), searchKeyword, 10);
|
||||
|
||||
mProgressBar.setVisibility(View.VISIBLE);
|
||||
|
||||
@ -141,16 +130,13 @@ public class AddNewTeamMemberActivity extends BaseActivity {
|
||||
dataList.addAll(response.body().getData());
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noData.setVisibility(View.GONE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
noData.setVisibility(View.VISIBLE);
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ 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.helpers.TinyDB;
|
||||
import org.mian.gitnex.viewmodels.AdminGetUsersViewModel;
|
||||
|
||||
/**
|
||||
@ -34,8 +33,6 @@ import org.mian.gitnex.viewmodels.AdminGetUsersViewModel;
|
||||
public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAdminUsersFragment.BottomSheetListener {
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private AdminGetUsersAdapter adapter;
|
||||
private RecyclerView mRecyclerView;
|
||||
private TextView noDataUsers;
|
||||
@ -50,12 +47,6 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAd
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
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");
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
noDataUsers = findViewById(R.id.noDataUsers);
|
||||
@ -79,30 +70,30 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAd
|
||||
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
swipeRefresh.setRefreshing(false);
|
||||
AdminGetUsersViewModel.loadUsersList(ctx, instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken));
|
||||
AdminGetUsersViewModel.loadUsersList(ctx, Authorization.get(ctx));
|
||||
|
||||
}, 500));
|
||||
|
||||
fetchDataAsync(ctx, instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken));
|
||||
fetchDataAsync(ctx, Authorization.get(ctx));
|
||||
|
||||
}
|
||||
|
||||
private void fetchDataAsync(Context ctx, String instanceUrl, String instanceToken) {
|
||||
private void fetchDataAsync(Context ctx, String instanceToken) {
|
||||
|
||||
AdminGetUsersViewModel usersModel = new ViewModelProvider(this).get(AdminGetUsersViewModel.class);
|
||||
|
||||
usersModel.getUsersList(ctx, instanceUrl, instanceToken).observe(this, usersListMain -> {
|
||||
usersModel.getUsersList(ctx, instanceToken).observe(this, usersListMain -> {
|
||||
|
||||
adapter = new AdminGetUsersAdapter(ctx, usersListMain);
|
||||
if(adapter.getItemCount() > 0) {
|
||||
|
||||
mRecyclerView.setVisibility(View.VISIBLE);
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
noDataUsers.setVisibility(View.GONE);
|
||||
searchFilter = true;
|
||||
}
|
||||
else {
|
||||
//adapter.notifyDataSetChanged();
|
||||
//mRecyclerView.setAdapter(adapter);
|
||||
|
||||
mRecyclerView.setVisibility(View.GONE);
|
||||
noDataUsers.setVisibility(View.VISIBLE);
|
||||
}
|
||||
@ -140,6 +131,7 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAd
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
|
||||
adapter.getFilter().filter(newText);
|
||||
return false;
|
||||
}
|
||||
@ -157,18 +149,21 @@ public class AdminGetUsersActivity extends BaseActivity implements BottomSheetAd
|
||||
|
||||
int id = item.getItemId();
|
||||
|
||||
switch (id) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.genericMenu:
|
||||
BottomSheetAdminUsersFragment bottomSheet = new BottomSheetAdminUsersFragment();
|
||||
bottomSheet.show(getSupportFragmentManager(), "usersBottomSheet");
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
if(id == android.R.id.home) {
|
||||
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
else if(id == R.id.genericMenu) {
|
||||
|
||||
BottomSheetAdminUsersFragment bottomSheet = new BottomSheetAdminUsersFragment();
|
||||
bottomSheet.show(getSupportFragmentManager(), "usersBottomSheet");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
@ -14,6 +15,7 @@ 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.StaticGlobalVariables;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.notifications.NotificationsMaster;
|
||||
@ -25,6 +27,7 @@ import static org.acra.ReportField.STACK_TRACE;
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
@SuppressLint("NonConstantResourceId")
|
||||
@AcraNotification(resIcon = R.drawable.gitnex_transparent,
|
||||
resTitle = R.string.crashTitle,
|
||||
resChannelName = R.string.setCrashReports,
|
||||
@ -33,119 +36,144 @@ import static org.acra.ReportField.STACK_TRACE;
|
||||
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
|
||||
private Context appCtx;
|
||||
protected TinyDB tinyDB;
|
||||
|
||||
protected Context ctx = this;
|
||||
protected Context appCtx;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
appCtx = getApplicationContext();
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
this.appCtx = getApplicationContext();
|
||||
this.tinyDB = TinyDB.getInstance(appCtx);
|
||||
|
||||
switch(tinyDb.getInt("themeId")) {
|
||||
switch(tinyDB.getInt("themeId")) {
|
||||
|
||||
case 1:
|
||||
|
||||
tinyDB.putString("currentTheme", "light");
|
||||
setTheme(R.style.AppThemeLight);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
if(TimeHelper.timeBetweenHours(18, 6)) { // 6pm to 6am
|
||||
|
||||
tinyDB.putString("currentTheme", "dark");
|
||||
setTheme(R.style.AppTheme);
|
||||
}
|
||||
else {
|
||||
|
||||
tinyDB.putString("currentTheme", "light");
|
||||
setTheme(R.style.AppThemeLight);
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
tinyDB.putString("currentTheme", "light");
|
||||
setTheme(R.style.AppThemeRetro);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if(TimeHelper.timeBetweenHours(18, 6)) { // 6pm to 6am
|
||||
|
||||
tinyDB.putString("currentTheme", "dark");
|
||||
setTheme(R.style.AppTheme);
|
||||
}
|
||||
else {
|
||||
|
||||
tinyDB.putString("currentTheme", "light");
|
||||
setTheme(R.style.AppThemeRetro);
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
|
||||
default:
|
||||
setTheme(R.style.AppTheme);
|
||||
tinyDB.putString("currentTheme", "dark");
|
||||
setTheme(R.style.AppThemePitchBlack);
|
||||
break;
|
||||
default:
|
||||
|
||||
tinyDB.putString("currentTheme", "dark");
|
||||
setTheme(R.style.AppTheme);
|
||||
|
||||
}
|
||||
|
||||
String appLocale = tinyDb.getString("locale");
|
||||
String appLocale = tinyDB.getString("locale");
|
||||
AppUtil.setAppLocale(getResources(), appLocale);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getLayoutResourceId());
|
||||
|
||||
switch(tinyDb.getInt("customFontId", -1)) {
|
||||
// FIXME Performance nightmare
|
||||
switch(tinyDB.getInt("customFontId", -1)) {
|
||||
|
||||
case 0:
|
||||
|
||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/roboto.ttf");
|
||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/roboto.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/roboto.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/roboto.ttf");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/sourcecodeproregular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/sourcecodeproregular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/sourcecodeproregular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/sourcecodeproregular.ttf");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
FontsOverride.setDefaultFont(this, "DEFAULT", "fonts/manroperegular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "MONOSPACE", "fonts/manroperegular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SERIF", "fonts/manroperegular.ttf");
|
||||
FontsOverride.setDefaultFont(this, "SANS_SERIF", "fonts/manroperegular.ttf");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if(tinyDb.getInt("pollingDelayMinutes") == 0) {
|
||||
tinyDb.putInt("pollingDelayMinutes", 15);
|
||||
if(tinyDB.getInt("pollingDelayMinutes", 0) <= 0) {
|
||||
|
||||
tinyDB.putInt("pollingDelayMinutes", StaticGlobalVariables.defaultPollingDelay);
|
||||
}
|
||||
|
||||
// FIXME Performance nightmare
|
||||
NotificationsMaster.hireWorker(appCtx);
|
||||
|
||||
// enabling counter badges by default
|
||||
if(tinyDb.getString("enableCounterBadgesInit").isEmpty()) {
|
||||
tinyDb.putBoolean("enableCounterBadges", true);
|
||||
tinyDb.putString("enableCounterBadgesInit", "yes");
|
||||
if(tinyDB.getString("enableCounterBadgesInit").isEmpty()) {
|
||||
|
||||
tinyDB.putBoolean("enableCounterBadges", true);
|
||||
tinyDB.putString("enableCounterBadgesInit", "yes");
|
||||
}
|
||||
|
||||
// enable crash reports by default
|
||||
if(tinyDb.getString("crashReportingEnabledInit").isEmpty()) {
|
||||
tinyDb.putBoolean("crashReportingEnabled", true);
|
||||
tinyDb.putString("crashReportingEnabledInit", "yes");
|
||||
if(tinyDB.getString("crashReportingEnabledInit").isEmpty()) {
|
||||
|
||||
tinyDB.putBoolean("crashReportingEnabled", true);
|
||||
tinyDB.putString("crashReportingEnabledInit", "yes");
|
||||
}
|
||||
|
||||
// default cache setter
|
||||
if(tinyDb.getString("cacheSizeStr").isEmpty()) {
|
||||
tinyDb.putString("cacheSizeStr", getResources().getString(R.string.cacheSizeDataSelectionSelectedText));
|
||||
if(tinyDB.getString("cacheSizeStr").isEmpty()) {
|
||||
|
||||
tinyDB.putString("cacheSizeStr", getResources().getString(R.string.cacheSizeDataSelectionSelectedText));
|
||||
}
|
||||
if(tinyDb.getString("cacheSizeImagesStr").isEmpty()) {
|
||||
tinyDb.putString("cacheSizeImagesStr", getResources().getString(R.string.cacheSizeImagesSelectionSelectedText));
|
||||
if(tinyDB.getString("cacheSizeImagesStr").isEmpty()) {
|
||||
|
||||
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("draftsCommentsDeletionEnabledInit").isEmpty()) {
|
||||
|
||||
tinyDB.putBoolean("draftsCommentsDeletionEnabled", true);
|
||||
tinyDB.putString("draftsCommentsDeletionEnabledInit", "yes");
|
||||
}
|
||||
|
||||
if (tinyDb.getBoolean("crashReportingEnabled")) {
|
||||
// FIXME Performance nightmare
|
||||
if (tinyDB.getBoolean("crashReportingEnabled")) {
|
||||
|
||||
CoreConfigurationBuilder ACRABuilder = new CoreConfigurationBuilder(this);
|
||||
ACRABuilder.setBuildConfigClass(BuildConfig.class).setReportFormat(StringFormat.KEY_VALUE_LIST);
|
||||
ACRABuilder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class).setReportAsFile(true).setMailTo(getResources().getString(R.string.appEmail)).setSubject(getResources().getString(R.string.crashReportEmailSubject, AppUtil.getAppBuildNo(getApplicationContext()))).setEnabled(true);
|
||||
ACRABuilder.getPluginConfigurationBuilder(LimiterConfigurationBuilder.class).setEnabled(true);
|
||||
ACRA.init(getApplication(), ACRABuilder);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -21,13 +20,11 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.adapters.CommitsAdapter;
|
||||
import org.mian.gitnex.clients.AppApiService;
|
||||
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.Toasty;
|
||||
import org.mian.gitnex.helpers.Version;
|
||||
import org.mian.gitnex.interfaces.ApiInterface;
|
||||
import org.mian.gitnex.models.Commits;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -41,8 +38,6 @@ import retrofit2.Response;
|
||||
|
||||
public class CommitsActivity extends BaseActivity {
|
||||
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private View.OnClickListener onClickListener;
|
||||
private TextView noData;
|
||||
private ProgressBar progressBar;
|
||||
@ -53,7 +48,6 @@ public class CommitsActivity extends BaseActivity {
|
||||
private RecyclerView recyclerView;
|
||||
private List<Commits> commitsList;
|
||||
private CommitsAdapter adapter;
|
||||
private ApiInterface api;
|
||||
private ProgressBar progressLoadMore;
|
||||
|
||||
@Override
|
||||
@ -66,15 +60,10 @@ public class CommitsActivity extends BaseActivity {
|
||||
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 repoFullName = tinyDb.getString("repoFullName");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
@ -95,7 +84,8 @@ public class CommitsActivity extends BaseActivity {
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
// if gitea is 1.12 or higher use the new limit (resultLimitNewGiteaInstances)
|
||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12")) {
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12")) {
|
||||
|
||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
||||
}
|
||||
|
||||
@ -105,9 +95,8 @@ public class CommitsActivity extends BaseActivity {
|
||||
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
swipeRefresh.setRefreshing(false);
|
||||
loadInitial(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, branchName, resultLimit);
|
||||
loadInitial(Authorization.get(ctx), repoOwner, repoName, branchName, resultLimit);
|
||||
adapter.notifyDataChanged();
|
||||
|
||||
}, 200));
|
||||
|
||||
adapter = new CommitsAdapter(ctx, commitsList);
|
||||
@ -116,23 +105,20 @@ public class CommitsActivity extends BaseActivity {
|
||||
if(commitsList.size() == resultLimit || pageSize == resultLimit) {
|
||||
|
||||
int page = (commitsList.size() + resultLimit) / resultLimit;
|
||||
loadMore(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, page, branchName, resultLimit);
|
||||
loadMore(Authorization.get(ctx), repoOwner, repoName, page, branchName, resultLimit);
|
||||
}
|
||||
|
||||
}));
|
||||
|
||||
recyclerView.setHasFixedSize(true);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
api = AppApiService.createService(ApiInterface.class, instanceUrl, ctx);
|
||||
loadInitial(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, branchName, resultLimit);
|
||||
|
||||
loadInitial(Authorization.get(ctx), repoOwner, repoName, branchName, resultLimit);
|
||||
}
|
||||
|
||||
private void loadInitial(String token, String repoOwner, String repoName, String branchName, int resultLimit) {
|
||||
|
||||
Call<List<Commits>> call = api.getRepositoryCommits(token, repoOwner, repoName, 1, branchName, resultLimit);
|
||||
Call<List<Commits>> call = RetrofitClient.getApiInterface(ctx).getRepositoryCommits(token, repoOwner, repoName, 1, branchName, resultLimit);
|
||||
|
||||
call.enqueue(new Callback<List<Commits>>() {
|
||||
|
||||
@ -148,7 +134,6 @@ public class CommitsActivity extends BaseActivity {
|
||||
commitsList.addAll(response.body());
|
||||
adapter.notifyDataChanged();
|
||||
noData.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@ -164,7 +149,6 @@ public class CommitsActivity extends BaseActivity {
|
||||
else {
|
||||
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
|
||||
}
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
@ -184,7 +168,7 @@ public class CommitsActivity extends BaseActivity {
|
||||
|
||||
progressLoadMore.setVisibility(View.VISIBLE);
|
||||
|
||||
Call<List<Commits>> call = api.getRepositoryCommits(token, repoOwner, repoName, page, branchName, resultLimit);
|
||||
Call<List<Commits>> call = RetrofitClient.getApiInterface(ctx).getRepositoryCommits(token, repoOwner, repoName, page, branchName, resultLimit);
|
||||
|
||||
call.enqueue(new Callback<List<Commits>>() {
|
||||
|
||||
@ -211,7 +195,6 @@ public class CommitsActivity extends BaseActivity {
|
||||
else {
|
||||
|
||||
Log.e(TAG, String.valueOf(response.code()));
|
||||
|
||||
}
|
||||
|
||||
progressLoadMore.setVisibility(View.GONE);
|
||||
@ -255,7 +238,6 @@ public class CommitsActivity extends BaseActivity {
|
||||
});
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
|
||||
}
|
||||
|
||||
private void filter(String text) {
|
||||
@ -263,7 +245,9 @@ public class CommitsActivity extends BaseActivity {
|
||||
List<Commits> arr = new ArrayList<>();
|
||||
|
||||
for(Commits d : commitsList) {
|
||||
|
||||
if(d.getCommit().getMessage().toLowerCase().contains(text) || d.getSha().toLowerCase().contains(text)) {
|
||||
|
||||
arr.add(d);
|
||||
}
|
||||
}
|
||||
@ -274,6 +258,7 @@ public class CommitsActivity extends BaseActivity {
|
||||
private void initCloseListener() {
|
||||
|
||||
onClickListener = view -> {
|
||||
|
||||
getIntent().removeExtra("branchName");
|
||||
finish();
|
||||
};
|
||||
|
@ -1,16 +1,17 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
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;
|
||||
@ -19,7 +20,6 @@ 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;
|
||||
@ -44,49 +44,48 @@ public class CreateFileActivity extends BaseActivity {
|
||||
private EditText newFileContent;
|
||||
private EditText newFileBranchName;
|
||||
private EditText newFileCommitMessage;
|
||||
private Spinner newFileBranchesSpinner;
|
||||
private AutoCompleteTextView 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<>();
|
||||
|
||||
private String loginUid;
|
||||
private String repoOwner;
|
||||
private String repoName;
|
||||
private String instanceToken;
|
||||
|
||||
private String selectedBranch;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_new_file;
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
tinyDb = new TinyDB(appCtx);
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
loginUid = tinyDB.getString("loginUid");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
repoOwner = parts[0];
|
||||
repoName = parts[1];
|
||||
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||
|
||||
closeActivity = findViewById(R.id.close);
|
||||
newFileName = findViewById(R.id.newFileName);
|
||||
newFileContent = findViewById(R.id.newFileContent);
|
||||
newFileBranchName = findViewById(R.id.newFileBranchName);
|
||||
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;
|
||||
@ -97,9 +96,19 @@ public class CreateFileActivity extends BaseActivity {
|
||||
|
||||
newFileCreate = findViewById(R.id.newFileCreate);
|
||||
|
||||
newFileContent.setOnTouchListener((touchView, motionEvent) -> {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
|
||||
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if(getIntent().getStringExtra("filePath") != null && getIntent().getIntExtra("fileAction", 1) == 1) {
|
||||
|
||||
fileNameHint.setVisibility(View.GONE);
|
||||
fileAction = getIntent().getIntExtra("fileAction", 1);
|
||||
|
||||
filePath = getIntent().getStringExtra("filePath");
|
||||
@ -120,7 +129,6 @@ public class CreateFileActivity extends BaseActivity {
|
||||
|
||||
if(getIntent().getStringExtra("filePath") != null && getIntent().getIntExtra("fileAction", 2) == 2) {
|
||||
|
||||
fileNameHint.setVisibility(View.GONE);
|
||||
fileAction = getIntent().getIntExtra("fileAction", 2);
|
||||
|
||||
filePath = getIntent().getStringExtra("filePath");
|
||||
@ -141,33 +149,7 @@ public class CreateFileActivity extends BaseActivity {
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
newFileBranchesSpinner = findViewById(R.id.newFileBranchesSpinner);
|
||||
getBranches(instanceUrl, instanceToken, repoOwner, repoName, loginUid);
|
||||
|
||||
newFileBranchesSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
|
||||
{
|
||||
public void onItemSelected(AdapterView<?> arg0,
|
||||
View arg1, int arg2, long arg3)
|
||||
{
|
||||
Branches bModelValue = (Branches) newFileBranchesSpinner.getSelectedItem();
|
||||
|
||||
if(bModelValue.toString().equals("No branch")) {
|
||||
newFileBranchName.setEnabled(true);
|
||||
newFileBranchName.setVisibility(View.VISIBLE);
|
||||
branchNameId.setVisibility(View.VISIBLE);
|
||||
branchNameHintText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
newFileBranchName.setEnabled(false);
|
||||
newFileBranchName.setVisibility(View.GONE);
|
||||
branchNameId.setVisibility(View.GONE);
|
||||
branchNameHintText.setVisibility(View.GONE);
|
||||
newFileBranchName.setText("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView<?> arg0) {}
|
||||
});
|
||||
getBranches(instanceToken, repoOwner, repoName, loginUid);
|
||||
|
||||
disableProcessButton();
|
||||
|
||||
@ -182,54 +164,43 @@ public class CreateFileActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
private View.OnClickListener createFileListener = v -> processNewFile();
|
||||
private final View.OnClickListener createFileListener = v -> processNewFile();
|
||||
|
||||
private void processNewFile() {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
AppUtil appUtil = new AppUtil();
|
||||
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];
|
||||
|
||||
String newFileName_ = newFileName.getText().toString();
|
||||
String newFileContent_ = newFileContent.getText().toString();
|
||||
String newFileBranchName_ = newFileBranchName.getText().toString();
|
||||
String newFileCommitMessage_ = newFileCommitMessage.getText().toString();
|
||||
|
||||
Branches currentBranch = (Branches) newFileBranchesSpinner.getSelectedItem();
|
||||
|
||||
if(!connToInternet) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(newFileName_.equals("") || newFileContent_.equals("") || newFileCommitMessage_.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.newFileRequiredFields));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(currentBranch.toString().equals("No branch")) {
|
||||
if(selectedBranch.equals("No branch")) {
|
||||
|
||||
if(newFileBranchName_.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.newFileRequiredFieldNewBranchName));
|
||||
return;
|
||||
}
|
||||
else {
|
||||
|
||||
if(!appUtil.checkStringsWithDash(newFileBranchName_)) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.newFileInvalidBranchName));
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,7 +209,6 @@ public class CreateFileActivity extends BaseActivity {
|
||||
if(appUtil.charactersLength(newFileCommitMessage_) > 255) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.newFileCommitMessageError));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@ -246,37 +216,38 @@ public class CreateFileActivity extends BaseActivity {
|
||||
|
||||
if(fileAction == 1) {
|
||||
|
||||
deleteFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, filePath,
|
||||
newFileBranchName_, newFileCommitMessage_, currentBranch.toString(), fileSha);
|
||||
deleteFile(Authorization.get(ctx), repoOwner, repoName, filePath,
|
||||
newFileBranchName_, newFileCommitMessage_, selectedBranch, fileSha);
|
||||
}
|
||||
else if(fileAction == 2) {
|
||||
|
||||
editFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, filePath,
|
||||
appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, currentBranch.toString(), fileSha);
|
||||
editFile(Authorization.get(ctx), repoOwner, repoName, filePath,
|
||||
appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, selectedBranch, fileSha);
|
||||
}
|
||||
else {
|
||||
|
||||
createNewFile(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, newFileName_,
|
||||
appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, currentBranch.toString());
|
||||
createNewFile(Authorization.get(ctx), repoOwner, repoName, newFileName_,
|
||||
appUtil.encodeBase64(newFileContent_), newFileBranchName_, newFileCommitMessage_, selectedBranch);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createNewFile(final String instanceUrl, final String token, String repoOwner, String repoName, String fileName, String fileContent, String fileBranchName, String fileCommitMessage, String currentBranch) {
|
||||
private void createNewFile(final String token, String repoOwner, String repoName, String fileName, String fileContent, String fileBranchName, String fileCommitMessage, String currentBranch) {
|
||||
|
||||
NewFile createNewFileJsonStr;
|
||||
if(currentBranch.equals("No branch")) {
|
||||
|
||||
createNewFileJsonStr = new NewFile("", fileContent, fileCommitMessage, fileBranchName);
|
||||
}
|
||||
else {
|
||||
|
||||
createNewFileJsonStr = new NewFile(currentBranch, fileContent, fileCommitMessage, "");
|
||||
}
|
||||
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.createNewFile(token, repoOwner, repoName, fileName, createNewFileJsonStr);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
@ -289,7 +260,6 @@ public class CreateFileActivity extends BaseActivity {
|
||||
enableProcessButton();
|
||||
Toasty.success(ctx, getString(R.string.newFileSuccessMessage));
|
||||
finish();
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -298,21 +268,20 @@ public class CreateFileActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
if(response.code() == 404) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, getString(R.string.apiNotFound));
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.orgCreatedError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -325,10 +294,11 @@ 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) {
|
||||
private void deleteFile(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;
|
||||
@ -341,8 +311,7 @@ public class CreateFileActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.deleteFile(token, repoOwner, repoName, fileName, deleteFileJsonStr);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
@ -358,7 +327,6 @@ public class CreateFileActivity extends BaseActivity {
|
||||
getIntent().removeExtra("fileSha");
|
||||
getIntent().removeExtra("fileContents");
|
||||
finish();
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -367,7 +335,6 @@ public class CreateFileActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@ -381,9 +348,7 @@ public class CreateFileActivity extends BaseActivity {
|
||||
enableProcessButton();
|
||||
Toasty.info(ctx, getString(R.string.genericError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -396,10 +361,11 @@ public class CreateFileActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
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) {
|
||||
private void editFile(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;
|
||||
@ -412,8 +378,7 @@ public class CreateFileActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.editFile(token, repoOwner, repoName, fileName, editFileJsonStr);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
@ -428,9 +393,8 @@ public class CreateFileActivity extends BaseActivity {
|
||||
getIntent().removeExtra("filePath");
|
||||
getIntent().removeExtra("fileSha");
|
||||
getIntent().removeExtra("fileContents");
|
||||
tinyDb.putBoolean("fileModified", true);
|
||||
tinyDB.putBoolean("fileModified", true);
|
||||
finish();
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -439,7 +403,6 @@ public class CreateFileActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@ -453,9 +416,7 @@ public class CreateFileActivity extends BaseActivity {
|
||||
enableProcessButton();
|
||||
Toasty.info(ctx, getString(R.string.genericError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -468,12 +429,11 @@ public class CreateFileActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
private void getBranches(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid) {
|
||||
private void getBranches(String instanceToken, String repoOwner, String repoName, String loginUid) {
|
||||
|
||||
Call<List<Branches>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getBranches(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
||||
.getApiInterface(ctx)
|
||||
.getBranches(Authorization.get(ctx), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<List<Branches>>() {
|
||||
|
||||
@ -481,37 +441,53 @@ public class CreateFileActivity extends BaseActivity {
|
||||
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull retrofit2.Response<List<Branches>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.code() == 200) {
|
||||
|
||||
List<Branches> branchesList_ = response.body();
|
||||
|
||||
branchesList.add(new Branches("No branch"));
|
||||
assert branchesList_ != null;
|
||||
|
||||
if(branchesList_.size() > 0) {
|
||||
|
||||
for (int i = 0; i < branchesList_.size(); i++) {
|
||||
|
||||
Branches data = new Branches(
|
||||
branchesList_.get(i).getName()
|
||||
);
|
||||
Branches data = new Branches(branchesList_.get(i).getName());
|
||||
branchesList.add(data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ArrayAdapter<Branches> adapter = new ArrayAdapter<>(CreateFileActivity.this,
|
||||
R.layout.spinner_item, branchesList);
|
||||
R.layout.list_spinner_items, branchesList);
|
||||
|
||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
||||
newFileBranchesSpinner.setAdapter(adapter);
|
||||
enableProcessButton();
|
||||
|
||||
newFileBranchesSpinner.setOnItemClickListener ((parent, view, position, id) -> {
|
||||
|
||||
selectedBranch = branchesList.get(position).getName();
|
||||
|
||||
if(selectedBranch.equals("No branch")) {
|
||||
|
||||
newFileBranchName.setEnabled(true);
|
||||
newFileBranchName.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
|
||||
newFileBranchName.setEnabled(false);
|
||||
newFileBranchName.setVisibility(View.GONE);
|
||||
newFileBranchName.setText("");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Branches>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
}
|
||||
});
|
||||
@ -519,6 +495,7 @@ public class CreateFileActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
|
||||
onClickListener = view -> finish();
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
@ -7,6 +8,7 @@ import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
@ -49,9 +51,6 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
private CustomLabelsSelectionDialogBinding labelsBinding;
|
||||
private CustomAssigneesSelectionDialogBinding assigneesBinding;
|
||||
private View.OnClickListener onClickListener;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private TinyDB tinyDb;
|
||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
||||
private Dialog dialogLabels;
|
||||
private Dialog dialogAssignees;
|
||||
@ -59,9 +58,7 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
private String assigneesSetter;
|
||||
private int milestoneId;
|
||||
|
||||
private String instanceUrl;
|
||||
private String loginUid;
|
||||
private String instanceToken;
|
||||
private String repoOwner;
|
||||
private String repoName;
|
||||
|
||||
@ -79,12 +76,11 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
return R.layout.activity_create_issue;
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
tinyDb = new TinyDB(appCtx);
|
||||
|
||||
viewBinding = ActivityCreateIssueBinding.inflate(getLayoutInflater());
|
||||
View view = viewBinding.getRoot();
|
||||
@ -94,17 +90,14 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
instanceUrl = tinyDb.getString("instanceUrl");
|
||||
loginUid = tinyDb.getString("loginUid");
|
||||
final String loginFullName = tinyDb.getString("userFullname");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
loginUid = tinyDB.getString("loginUid");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
repoOwner = parts[0];
|
||||
repoName = parts[1];
|
||||
instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
// require gitea 1.12 or higher
|
||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
|
||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
||||
}
|
||||
@ -113,6 +106,17 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
assert imm != null;
|
||||
imm.showSoftInput(viewBinding.newIssueTitle, InputMethodManager.SHOW_IMPLICIT);
|
||||
|
||||
viewBinding.newIssueDescription.setOnTouchListener((touchView, motionEvent) -> {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
|
||||
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
labelsAdapter = new LabelsListAdapter(labelsList, CreateIssueActivity.this, labelsIds);
|
||||
assigneesAdapter = new AssigneesListAdapter(ctx, assigneesList, CreateIssueActivity.this, assigneesListData);
|
||||
|
||||
@ -123,17 +127,13 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
viewBinding.newIssueLabels.setOnClickListener(this);
|
||||
viewBinding.newIssueDueDate.setOnClickListener(this);
|
||||
|
||||
getMilestones(instanceUrl, instanceToken, repoOwner, repoName, loginUid, resultLimit);
|
||||
getMilestones(repoOwner, repoName, resultLimit);
|
||||
|
||||
disableProcessButton();
|
||||
|
||||
viewBinding.newIssueLabels.setOnClickListener(newIssueLabels ->
|
||||
showLabels()
|
||||
);
|
||||
viewBinding.newIssueLabels.setOnClickListener(newIssueLabels -> showLabels());
|
||||
|
||||
viewBinding.newIssueAssigneesList.setOnClickListener(newIssueAssigneesList ->
|
||||
showAssignees()
|
||||
);
|
||||
viewBinding.newIssueAssigneesList.setOnClickListener(newIssueAssigneesList -> showAssignees());
|
||||
|
||||
if(!connToInternet) {
|
||||
|
||||
@ -181,11 +181,10 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
View view = assigneesBinding.getRoot();
|
||||
dialogAssignees.setContentView(view);
|
||||
|
||||
assigneesBinding.cancel.setOnClickListener(assigneesBinding_ ->
|
||||
dialogAssignees.dismiss()
|
||||
);
|
||||
assigneesBinding.cancel.setOnClickListener(assigneesBinding_ -> dialogAssignees.dismiss());
|
||||
|
||||
AssigneesActions.getRepositoryAssignees(ctx, instanceUrl, instanceToken, repoOwner, repoName, assigneesList, dialogAssignees, assigneesAdapter, assigneesBinding);
|
||||
dialogAssignees.show();
|
||||
AssigneesActions.getRepositoryAssignees(ctx, repoOwner, repoName, assigneesList, dialogAssignees, assigneesAdapter, assigneesBinding);
|
||||
}
|
||||
|
||||
private void showLabels() {
|
||||
@ -202,11 +201,10 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
View view = labelsBinding.getRoot();
|
||||
dialogLabels.setContentView(view);
|
||||
|
||||
labelsBinding.cancel.setOnClickListener(labelsBinding_ ->
|
||||
dialogLabels.dismiss()
|
||||
);
|
||||
labelsBinding.cancel.setOnClickListener(labelsBinding_ -> dialogLabels.dismiss());
|
||||
|
||||
LabelsActions.getRepositoryLabels(ctx, instanceUrl, instanceToken, repoOwner, repoName, labelsList, dialogLabels, labelsAdapter, labelsBinding);
|
||||
dialogLabels.show();
|
||||
LabelsActions.getRepositoryLabels(ctx, repoOwner, repoName, labelsList, dialogLabels, labelsAdapter, labelsBinding);
|
||||
}
|
||||
|
||||
private void processNewIssue() {
|
||||
@ -221,7 +219,6 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (newIssueTitleForm.equals("")) {
|
||||
@ -240,20 +237,18 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
}
|
||||
|
||||
disableProcessButton();
|
||||
createNewIssueFunc(instanceUrl, instanceToken, repoOwner, repoName, loginUid, newIssueDescriptionForm, newIssueDueDateForm, milestoneId, newIssueTitleForm);
|
||||
|
||||
createNewIssueFunc(repoOwner, repoName, loginUid, newIssueDescriptionForm, newIssueDueDateForm, milestoneId, newIssueTitleForm);
|
||||
}
|
||||
|
||||
private void createNewIssueFunc(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String loginUid, String newIssueDescriptionForm, String newIssueDueDateForm, int newIssueMilestoneIdForm, String newIssueTitleForm) {
|
||||
private void createNewIssueFunc(String repoOwner, String repoName, String loginUid, String newIssueDescriptionForm, String newIssueDueDateForm, int newIssueMilestoneIdForm, String newIssueTitleForm) {
|
||||
|
||||
CreateIssue createNewIssueJson = new CreateIssue(loginUid, newIssueDescriptionForm, false, newIssueDueDateForm, newIssueMilestoneIdForm, newIssueTitleForm, assigneesListData, labelsIds);
|
||||
|
||||
Call<JsonElement> call3;
|
||||
|
||||
call3 = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.createNewIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, createNewIssueJson);
|
||||
.getApiInterface(ctx)
|
||||
.createNewIssue(Authorization.get(ctx), repoOwner, repoName, createNewIssueJson);
|
||||
|
||||
call3.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -262,7 +257,7 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
|
||||
if(response2.code() == 201) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
|
||||
Toasty.success(ctx, getString(R.string.issueCreated));
|
||||
@ -300,13 +295,12 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
onClickListener = view -> finish();
|
||||
}
|
||||
|
||||
private void getMilestones(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid, int resultLimit) {
|
||||
private void getMilestones(String repoOwner, String repoName, int resultLimit) {
|
||||
|
||||
String msState = "open";
|
||||
Call<List<Milestones>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getMilestones(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, 1, resultLimit, msState);
|
||||
.getApiInterface(ctx)
|
||||
.getMilestones(Authorization.get(ctx), repoOwner, repoName, 1, resultLimit, msState);
|
||||
|
||||
call.enqueue(new Callback<List<Milestones>>() {
|
||||
|
||||
@ -314,13 +308,16 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
public void onResponse(@NonNull Call<List<Milestones>> call, @NonNull retrofit2.Response<List<Milestones>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.code() == 200) {
|
||||
|
||||
List<Milestones> milestonesList_ = response.body();
|
||||
|
||||
milestonesList.add(new Milestones(0,getString(R.string.issueCreatedNoMilestone)));
|
||||
assert milestonesList_ != null;
|
||||
|
||||
if(milestonesList_.size() > 0) {
|
||||
|
||||
for (int i = 0; i < milestonesList_.size(); i++) {
|
||||
|
||||
//Don't translate "open" is a enum
|
||||
@ -331,7 +328,6 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
);
|
||||
milestonesList.add(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -375,9 +371,9 @@ public class CreateIssueActivity extends BaseActivity implements View.OnClickLis
|
||||
datePickerDialog.show();
|
||||
}
|
||||
else if(v == viewBinding.createNewIssueButton) {
|
||||
|
||||
processNewIssue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void disableProcessButton() {
|
||||
|
@ -10,11 +10,9 @@ 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;
|
||||
@ -25,6 +23,7 @@ import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.models.CreateLabel;
|
||||
import org.mian.gitnex.models.Labels;
|
||||
import org.mian.gitnex.viewmodels.LabelsViewModel;
|
||||
import org.mian.gitnex.viewmodels.OrganizationLabelsViewModel;
|
||||
import java.util.Objects;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
@ -39,8 +38,7 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
private TextView colorPicker;
|
||||
private EditText labelName;
|
||||
private Button createLabelButton;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private TinyDB tinyDB;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
@ -51,25 +49,20 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
tinyDB = TinyDB.getInstance(appCtx);
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
if(getIntent().getStringExtra("labelAction") != null && Objects.requireNonNull(getIntent().getStringExtra("labelAction")).equals("delete")) {
|
||||
|
||||
deleteLabel(instanceUrl, instanceToken, repoOwner, repoName, Integer.parseInt(Objects.requireNonNull(getIntent().getStringExtra("labelId"))), loginUid);
|
||||
deleteLabel(repoOwner, repoName, Integer.parseInt(Objects.requireNonNull(getIntent().getStringExtra("labelId"))));
|
||||
finish();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
@ -87,22 +80,14 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
|
||||
initCloseListener();
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
colorPicker.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
cp.show();
|
||||
}
|
||||
});
|
||||
colorPicker.setOnClickListener(v -> cp.show());
|
||||
|
||||
cp.setCallback(new ColorPickerCallback() {
|
||||
@Override
|
||||
public void onColorChosen(@ColorInt int color) {
|
||||
cp.setCallback(color -> {
|
||||
|
||||
//Log.i("#Hex no alpha", String.format("#%06X", (0xFFFFFF & color)));
|
||||
colorPicker.setBackgroundColor(color);
|
||||
tinyDb.putString("labelColor", String.format("#%06X", (0xFFFFFF & color)));
|
||||
cp.dismiss();
|
||||
|
||||
}
|
||||
//Log.i("#Hex no alpha", String.format("#%06X", (0xFFFFFF & color)));
|
||||
colorPicker.setBackgroundColor(color);
|
||||
tinyDB.putString("labelColor", String.format("#%06X", (0xFFFFFF & color)));
|
||||
cp.dismiss();
|
||||
});
|
||||
|
||||
if(getIntent().getStringExtra("labelAction") != null && Objects.requireNonNull(getIntent().getStringExtra("labelAction")).equals("edit")) {
|
||||
@ -110,7 +95,7 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
labelName.setText(getIntent().getStringExtra("labelTitle"));
|
||||
int labelColor_ = Color.parseColor("#" + getIntent().getStringExtra("labelColor"));
|
||||
colorPicker.setBackgroundColor(labelColor_);
|
||||
tinyDb.putString("labelColorDefault", "#" + getIntent().getStringExtra("labelColor"));
|
||||
tinyDB.putString("labelColorDefault", "#" + getIntent().getStringExtra("labelColor"));
|
||||
|
||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
||||
toolbar_title.setText(getResources().getString(R.string.pageTitleLabelUpdate));
|
||||
@ -131,57 +116,52 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
private View.OnClickListener createLabelListener = v -> processCreateLabel();
|
||||
private final View.OnClickListener createLabelListener = v -> processCreateLabel();
|
||||
|
||||
private View.OnClickListener updateLabelListener = v -> processUpdateLabel();
|
||||
private final View.OnClickListener updateLabelListener = v -> processUpdateLabel();
|
||||
|
||||
private void processUpdateLabel() {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
AppUtil appUtil = new AppUtil();
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
String updateLabelName = labelName.getText().toString();
|
||||
|
||||
String updateLabelColor;
|
||||
if(tinyDb.getString("labelColor").isEmpty()) {
|
||||
updateLabelColor = tinyDb.getString("labelColorDefault");
|
||||
if(tinyDB.getString("labelColor").isEmpty()) {
|
||||
|
||||
updateLabelColor = tinyDB.getString("labelColorDefault");
|
||||
}
|
||||
else {
|
||||
updateLabelColor = tinyDb.getString("labelColor");
|
||||
|
||||
updateLabelColor = tinyDB.getString("labelColor");
|
||||
}
|
||||
|
||||
if(!connToInternet) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(updateLabelName.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.labelEmptyError));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(!appUtil.checkStrings(updateLabelName)) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.labelNameError));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
disableProcessButton();
|
||||
patchLabel(instanceUrl, instanceToken, repoOwner, repoName, updateLabelName, updateLabelColor, Integer.parseInt(
|
||||
Objects.requireNonNull(getIntent().getStringExtra("labelId"))), loginUid);
|
||||
patchLabel(repoOwner, repoName, updateLabelName, updateLabelColor, Integer.parseInt(
|
||||
Objects.requireNonNull(getIntent().getStringExtra("labelId"))));
|
||||
|
||||
}
|
||||
|
||||
@ -189,61 +169,60 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
AppUtil appUtil = new AppUtil();
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
String newLabelName = labelName.getText().toString();
|
||||
String newLabelColor;
|
||||
if(tinyDb.getString("labelColor").isEmpty()) {
|
||||
|
||||
if(tinyDB.getString("labelColor").isEmpty()) {
|
||||
|
||||
newLabelColor = String.format("#%06X", (0xFFFFFF & ContextCompat.getColor(ctx, R.color.releasePre)));
|
||||
}
|
||||
else {
|
||||
newLabelColor = tinyDb.getString("labelColor");
|
||||
|
||||
newLabelColor = tinyDB.getString("labelColor");
|
||||
}
|
||||
|
||||
if(!connToInternet) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(newLabelName.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.labelEmptyError));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(!appUtil.checkStrings(newLabelName)) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.labelNameError));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
disableProcessButton();
|
||||
createNewLabel(instanceUrl, instanceToken, repoOwner, repoName, newLabelName, newLabelColor, loginUid);
|
||||
|
||||
createNewLabel(repoOwner, repoName, newLabelName, newLabelColor);
|
||||
}
|
||||
|
||||
private void createNewLabel(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String newLabelName, String newLabelColor, String loginUid) {
|
||||
private void createNewLabel(String repoOwner, String repoName, String newLabelName, String newLabelColor) {
|
||||
|
||||
CreateLabel createLabelFunc = new CreateLabel(newLabelName, newLabelColor);
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
Call<CreateLabel> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.createLabel(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, createLabelFunc);
|
||||
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||
|
||||
call = RetrofitClient.getApiInterface(ctx).createOrganizationLabel(Authorization.get(ctx), getIntent().getStringExtra("orgName"), createLabelFunc);
|
||||
}
|
||||
else {
|
||||
|
||||
call = RetrofitClient.getApiInterface(ctx).createLabel(Authorization.get(ctx), repoOwner, repoName, createLabelFunc);
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<CreateLabel>() {
|
||||
|
||||
@ -253,10 +232,9 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
if(response.code() == 201) {
|
||||
|
||||
Toasty.success(ctx, getString(R.string.labelCreated));
|
||||
tinyDb.putString("labelColor", "");
|
||||
tinyDb.putBoolean("labelsRefresh", true);
|
||||
tinyDB.putString("labelColor", "");
|
||||
tinyDB.putBoolean("labelsRefresh", true);
|
||||
finish();
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -265,22 +243,19 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
tinyDb.putString("labelColor", "");
|
||||
tinyDB.putString("labelColor", "");
|
||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
||||
|
||||
tinyDb.putString("labelColor", "");
|
||||
tinyDB.putString("labelColor", "");
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
}
|
||||
@ -288,17 +263,20 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
private void patchLabel(final String instanceUrl, final String instanceToken, String repoOwner, String repoName, String updateLabelName, String updateLabelColor, int labelId, String loginUid) {
|
||||
private void patchLabel(String repoOwner, String repoName, String updateLabelName, String updateLabelColor, int labelId) {
|
||||
|
||||
CreateLabel createLabelFunc = new CreateLabel(updateLabelName, updateLabelColor);
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
Call<CreateLabel> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.patchLabel(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, labelId, createLabelFunc);
|
||||
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||
|
||||
call = RetrofitClient.getApiInterface(ctx).patchOrganizationLabel(Authorization.get(ctx), getIntent().getStringExtra("orgName"), labelId, createLabelFunc);
|
||||
}
|
||||
else {
|
||||
|
||||
call = RetrofitClient.getApiInterface(appCtx).patchLabel(Authorization.get(ctx), repoOwner, repoName, labelId, createLabelFunc);
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<CreateLabel>() {
|
||||
|
||||
@ -306,18 +284,19 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
public void onResponse(@NonNull Call<CreateLabel> call, @NonNull retrofit2.Response<CreateLabel> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.code() == 200) {
|
||||
|
||||
Toasty.success(ctx, getString(R.string.labelUpdated));
|
||||
tinyDb.putString("labelColor", "");
|
||||
tinyDb.putBoolean("labelsRefresh", true);
|
||||
tinyDb.putString("labelColorDefault", "");
|
||||
tinyDB.putString("labelColor", "");
|
||||
tinyDB.putBoolean("labelsRefresh", true);
|
||||
tinyDB.putString("labelColorDefault", "");
|
||||
getIntent().removeExtra("labelAction");
|
||||
getIntent().removeExtra("labelId");
|
||||
getIntent().removeExtra("labelTitle");
|
||||
getIntent().removeExtra("labelColor");
|
||||
getIntent().removeExtra("type");
|
||||
finish();
|
||||
|
||||
}
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
@ -327,24 +306,21 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
tinyDb.putString("labelColor", "");
|
||||
tinyDb.putString("labelColorDefault", "");
|
||||
tinyDB.putString("labelColor", "");
|
||||
tinyDB.putString("labelColorDefault", "");
|
||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<CreateLabel> call, @NonNull Throwable t) {
|
||||
|
||||
tinyDb.putString("labelColor", "");
|
||||
tinyDb.putString("labelColorDefault", "");
|
||||
tinyDB.putString("labelColor", "");
|
||||
tinyDB.putString("labelColorDefault", "");
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
}
|
||||
@ -353,26 +329,30 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
getIntent().removeExtra("labelAction");
|
||||
getIntent().removeExtra("labelId");
|
||||
getIntent().removeExtra("labelTitle");
|
||||
getIntent().removeExtra("labelColor");
|
||||
finish();
|
||||
}
|
||||
|
||||
onClickListener = view -> {
|
||||
|
||||
getIntent().removeExtra("labelAction");
|
||||
getIntent().removeExtra("labelId");
|
||||
getIntent().removeExtra("labelTitle");
|
||||
getIntent().removeExtra("labelColor");
|
||||
getIntent().removeExtra("type");
|
||||
finish();
|
||||
};
|
||||
}
|
||||
|
||||
private void deleteLabel(final String instanceUrl, final String instanceToken, final String repoOwner, final String repoName, int labelId, String loginUid) {
|
||||
private void deleteLabel(final String repoOwner, final String repoName, int labelId) {
|
||||
|
||||
Call<Labels> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.deleteLabel(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, labelId);
|
||||
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||
|
||||
call = RetrofitClient.getApiInterface(appCtx).deleteOrganizationLabel(Authorization.get(ctx), getIntent().getStringExtra("orgName"), labelId);
|
||||
}
|
||||
else {
|
||||
|
||||
call = RetrofitClient.getApiInterface(appCtx).deleteLabel(Authorization.get(ctx), repoOwner, repoName, labelId);
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<Labels>() {
|
||||
|
||||
@ -380,13 +360,21 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
public void onResponse(@NonNull Call<Labels> call, @NonNull retrofit2.Response<Labels> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.code() == 204) {
|
||||
|
||||
Toasty.success(ctx, getString(R.string.labelDeleteText));
|
||||
LabelsViewModel.loadLabelsList(instanceUrl, instanceToken, repoOwner, repoName, ctx);
|
||||
if(getIntent().getStringExtra("type") != null && Objects.requireNonNull(getIntent().getStringExtra("type")).equals("org")) {
|
||||
|
||||
OrganizationLabelsViewModel.loadOrgLabelsList(Authorization.get(ctx), getIntent().getStringExtra("orgName"), ctx, null, null);
|
||||
}
|
||||
else {
|
||||
|
||||
LabelsViewModel.loadLabelsList(Authorization.get(ctx), repoOwner, repoName, ctx);
|
||||
}
|
||||
getIntent().removeExtra("labelAction");
|
||||
getIntent().removeExtra("labelId");
|
||||
|
||||
getIntent().removeExtra("type");
|
||||
}
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
@ -395,14 +383,11 @@ public class CreateLabelActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.labelDeleteErrorText));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,13 +1,14 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageView;
|
||||
import androidx.annotation.NonNull;
|
||||
@ -35,19 +36,17 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
||||
private EditText milestoneTitle;
|
||||
private EditText milestoneDescription;
|
||||
private Button createNewMilestoneButton;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_new_milestone;
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
|
||||
@ -63,6 +62,17 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
||||
assert imm != null;
|
||||
imm.showSoftInput(milestoneTitle, InputMethodManager.SHOW_IMPLICIT);
|
||||
|
||||
milestoneDescription.setOnTouchListener((touchView, motionEvent) -> {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
|
||||
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
initCloseListener();
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
milestoneDueDate.setOnClickListener(this);
|
||||
@ -78,21 +88,17 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
||||
|
||||
}
|
||||
|
||||
private View.OnClickListener createMilestoneListener = v -> processNewMilestone();
|
||||
private final View.OnClickListener createMilestoneListener = v -> processNewMilestone();
|
||||
|
||||
private void processNewMilestone() {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
AppUtil appUtil = new AppUtil();
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
//String appLocale = tinyDb.getString("locale");
|
||||
|
||||
String newMilestoneTitle = milestoneTitle.getText().toString();
|
||||
String newMilestoneDescription = milestoneDescription.getText().toString();
|
||||
@ -102,26 +108,25 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(newMilestoneTitle.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.milestoneNameErrorEmpty));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(!newMilestoneDescription.equals("")) {
|
||||
|
||||
if (appUtil.charactersLength(newMilestoneDescription) > 255) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.milestoneDescError));
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
String finalMilestoneDueDate = null;
|
||||
|
||||
if(!newMilestoneDueDate.isEmpty()) {
|
||||
|
||||
finalMilestoneDueDate = (AppUtil.customDateCombine(AppUtil.customDateFormat(newMilestoneDueDate)));
|
||||
@ -134,19 +139,17 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
|
||||
disableProcessButton();
|
||||
createNewMilestone(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, newMilestoneTitle, newMilestoneDescription, finalMilestoneDueDate);
|
||||
|
||||
createNewMilestone(Authorization.get(ctx), repoOwner, repoName, newMilestoneTitle, newMilestoneDescription, finalMilestoneDueDate);
|
||||
}
|
||||
|
||||
private void createNewMilestone(final String instanceUrl, final String token, String repoOwner, String repoName, String newMilestoneTitle, String newMilestoneDescription, String newMilestoneDueDate) {
|
||||
private void createNewMilestone(final String token, String repoOwner, String repoName, String newMilestoneTitle, String newMilestoneDescription, String newMilestoneDueDate) {
|
||||
|
||||
Milestones createMilestone = new Milestones(newMilestoneDescription, newMilestoneTitle, newMilestoneDueDate);
|
||||
|
||||
Call<Milestones> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(appCtx)
|
||||
.createMilestone(token, repoOwner, repoName, createMilestone);
|
||||
|
||||
call.enqueue(new Callback<Milestones>() {
|
||||
@ -155,14 +158,14 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
||||
public void onResponse(@NonNull Call<Milestones> call, @NonNull retrofit2.Response<Milestones> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.code() == 201) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
tinyDb.putBoolean("milestoneCreated", true);
|
||||
Toasty.success(ctx, getString(R.string.milestoneCreated));
|
||||
enableProcessButton();
|
||||
finish();
|
||||
|
||||
}
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
@ -172,19 +175,17 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.milestoneCreatedError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Milestones> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
}
|
||||
@ -203,16 +204,7 @@ public class CreateMilestoneActivity extends BaseActivity implements View.OnClic
|
||||
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
||||
|
||||
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
||||
new DatePickerDialog.OnDateSetListener() {
|
||||
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year,
|
||||
int monthOfYear, int dayOfMonth) {
|
||||
|
||||
milestoneDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth));
|
||||
|
||||
}
|
||||
}, mYear, mMonth, mDay);
|
||||
(view, year, monthOfYear, dayOfMonth) -> milestoneDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth)), mYear, mMonth, mDay);
|
||||
datePickerDialog.show();
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,6 @@ public class CreateNewUserActivity extends BaseActivity {
|
||||
private EditText userEmail;
|
||||
private EditText userPassword;
|
||||
private Button createUserButton;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
@ -45,7 +43,6 @@ public class CreateNewUserActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
|
||||
@ -73,17 +70,13 @@ public class CreateNewUserActivity extends BaseActivity {
|
||||
|
||||
createUserButton.setOnClickListener(createNewUserListener);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processCreateNewUser() {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
AppUtil appUtil = new AppUtil();
|
||||
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");
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
|
||||
String newFullName = fullName.getText().toString().trim();
|
||||
String newUserName = userUserName.getText().toString().trim();
|
||||
@ -94,51 +87,44 @@ public class CreateNewUserActivity extends BaseActivity {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(newFullName.equals("") || newUserName.equals("") | newUserEmail.equals("") || newUserPassword.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.emptyFields));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(!appUtil.checkStrings(newFullName)) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.userInvalidFullName));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(!appUtil.checkStringsWithAlphaNumeric(newUserName)) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.userInvalidUserName));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(!Patterns.EMAIL_ADDRESS.matcher(newUserEmail).matches()) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.userInvalidEmail));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
disableProcessButton();
|
||||
createNewUser(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), newFullName, newUserName, newUserEmail, newUserPassword);
|
||||
|
||||
createNewUser(Authorization.get(ctx), newFullName, newUserName, newUserEmail, newUserPassword);
|
||||
}
|
||||
|
||||
private void createNewUser(final String instanceUrl, final String instanceToken, String newFullName, String newUserName, String newUserEmail, String newUserPassword) {
|
||||
private void createNewUser(final String instanceToken, String newFullName, String newUserName, String newUserEmail, String newUserPassword) {
|
||||
|
||||
UserInfo createUser = new UserInfo(newUserEmail, newFullName, newUserName, newUserPassword, newUserName, 0, true);
|
||||
|
||||
Call<UserInfo> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(appCtx)
|
||||
.createNewUser(instanceToken, createUser);
|
||||
|
||||
call.enqueue(new Callback<UserInfo>() {
|
||||
@ -151,7 +137,6 @@ public class CreateNewUserActivity extends BaseActivity {
|
||||
Toasty.success(ctx, getString(R.string.userCreatedText));
|
||||
enableProcessButton();
|
||||
finish();
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -160,33 +145,27 @@ public class CreateNewUserActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
|
||||
}
|
||||
else if(response.code() == 404) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||
|
||||
}
|
||||
else if(response.code() == 422) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, ctx.getString(R.string.userExistsError));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.genericError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -199,7 +178,7 @@ public class CreateNewUserActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
private View.OnClickListener createNewUserListener = v -> processCreateNewUser();
|
||||
private final View.OnClickListener createNewUserListener = v -> processCreateNewUser();
|
||||
|
||||
private void initCloseListener() {
|
||||
|
||||
|
@ -1,8 +1,10 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
@ -32,19 +34,17 @@ public class CreateOrganizationActivity extends BaseActivity {
|
||||
|
||||
private EditText orgName;
|
||||
private EditText orgDesc;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_new_organization;
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
|
||||
@ -58,6 +58,17 @@ public class CreateOrganizationActivity extends BaseActivity {
|
||||
assert imm != null;
|
||||
imm.showSoftInput(orgName, InputMethodManager.SHOW_IMPLICIT);
|
||||
|
||||
orgDesc.setOnTouchListener((touchView, motionEvent) -> {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
|
||||
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
initCloseListener();
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
@ -75,28 +86,17 @@ public class CreateOrganizationActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
onClickListener = view -> finish();
|
||||
}
|
||||
|
||||
private View.OnClickListener createOrgListener = new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
processNewOrganization();
|
||||
}
|
||||
};
|
||||
private final View.OnClickListener createOrgListener = v -> processNewOrganization();
|
||||
|
||||
private void processNewOrganization() {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
AppUtil appUtil = new AppUtil();
|
||||
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");
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
|
||||
String newOrgName = orgName.getText().toString();
|
||||
String newOrgDesc = orgDesc.getText().toString();
|
||||
@ -105,44 +105,39 @@ public class CreateOrganizationActivity extends BaseActivity {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(!newOrgDesc.equals("")) {
|
||||
|
||||
if (appUtil.charactersLength(newOrgDesc) > 255) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.orgDescError));
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(newOrgName.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.orgNameErrorEmpty));
|
||||
|
||||
}
|
||||
else if(!appUtil.checkStrings(newOrgName)) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.orgNameErrorInvalid));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
disableProcessButton();
|
||||
createNewOrganization(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), newOrgName, newOrgDesc);
|
||||
|
||||
createNewOrganization(Authorization.get(ctx), newOrgName, newOrgDesc);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createNewOrganization(final String instanceUrl, final String token, String orgName, String orgDesc) {
|
||||
private void createNewOrganization(final String token, String orgName, String orgDesc) {
|
||||
|
||||
UserOrganizations createOrganization = new UserOrganizations(orgName, null, orgDesc, null, null);
|
||||
|
||||
Call<UserOrganizations> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(appCtx)
|
||||
.createNewOrganization(token, createOrganization);
|
||||
|
||||
call.enqueue(new Callback<UserOrganizations>() {
|
||||
@ -152,12 +147,11 @@ public class CreateOrganizationActivity extends BaseActivity {
|
||||
|
||||
if(response.code() == 201) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
tinyDb.putBoolean("orgCreated", true);
|
||||
enableProcessButton();
|
||||
Toasty.success(ctx, getString(R.string.orgCreated));
|
||||
finish();
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -166,37 +160,35 @@ public class CreateOrganizationActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else if(response.code() == 409) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, getString(R.string.orgExistsError));
|
||||
|
||||
}
|
||||
else if(response.code() == 422) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, getString(R.string.orgExistsError));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
if(response.code() == 404) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, getString(R.string.apiNotFound));
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.orgCreatedError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<UserOrganizations> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
@ -20,7 +21,6 @@ import org.mian.gitnex.databinding.CustomLabelsSelectionDialogBinding;
|
||||
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.Branches;
|
||||
@ -41,9 +41,6 @@ import retrofit2.Callback;
|
||||
public class CreatePullRequestActivity extends BaseActivity implements LabelsListAdapter.LabelsListAdapterListener {
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
private Context ctx = this;
|
||||
private Context appCtx;
|
||||
private TinyDB tinyDb;
|
||||
private ActivityCreatePrBinding viewBinding;
|
||||
private CustomLabelsSelectionDialogBinding labelsBinding;
|
||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
||||
@ -53,7 +50,6 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
private List<String> assignees = new ArrayList<>();
|
||||
private int milestoneId;
|
||||
|
||||
private String instanceUrl;
|
||||
private String loginUid;
|
||||
private String instanceToken;
|
||||
private String repoOwner;
|
||||
@ -73,30 +69,40 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
return R.layout.activity_create_pr;
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
tinyDb = new TinyDB(appCtx);
|
||||
|
||||
viewBinding = ActivityCreatePrBinding.inflate(getLayoutInflater());
|
||||
View view = viewBinding.getRoot();
|
||||
setContentView(view);
|
||||
|
||||
instanceUrl = tinyDb.getString("instanceUrl");
|
||||
loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
loginUid = tinyDB.getString("loginUid");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
repoOwner = parts[0];
|
||||
repoName = parts[1];
|
||||
instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||
|
||||
// require gitea 1.12 or higher
|
||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
|
||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
||||
}
|
||||
|
||||
viewBinding.prBody.setOnTouchListener((touchView, motionEvent) -> {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
|
||||
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
labelsAdapter = new LabelsListAdapter(labelsList, CreatePullRequestActivity.this, labelsIds);
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
@ -110,16 +116,12 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
|
||||
disableProcessButton();
|
||||
|
||||
getMilestones(instanceUrl, instanceToken, repoOwner, repoName, loginUid, resultLimit);
|
||||
getBranches(instanceUrl, instanceToken, repoOwner, repoName, loginUid);
|
||||
getMilestones(repoOwner, repoName, resultLimit);
|
||||
getBranches(repoOwner, repoName);
|
||||
|
||||
viewBinding.prLabels.setOnClickListener(prLabels ->
|
||||
showLabels()
|
||||
);
|
||||
viewBinding.prLabels.setOnClickListener(prLabels -> showLabels());
|
||||
|
||||
viewBinding.createPr.setOnClickListener(createPr ->
|
||||
processPullRequest()
|
||||
);
|
||||
viewBinding.createPr.setOnClickListener(createPr -> processPullRequest());
|
||||
}
|
||||
|
||||
private void processPullRequest() {
|
||||
@ -133,13 +135,16 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
assignees.add("");
|
||||
|
||||
if (labelsIds.size() == 0) {
|
||||
|
||||
labelsIds.add(0);
|
||||
}
|
||||
|
||||
if (dueDate.matches("")) {
|
||||
|
||||
dueDate = null;
|
||||
}
|
||||
else {
|
||||
|
||||
dueDate = AppUtil.customDateCombine(AppUtil.customDateFormat(dueDate));
|
||||
}
|
||||
|
||||
@ -160,9 +165,9 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
Toasty.error(ctx, getString(R.string.sameBranchesError));
|
||||
}
|
||||
else {
|
||||
|
||||
createPullRequest(prTitle, prDescription, mergeInto, pullFrom, milestoneId, dueDate, assignees);
|
||||
}
|
||||
//Log.e("processPullRequest", String.valueOf(milestoneId));
|
||||
}
|
||||
|
||||
private void createPullRequest(String prTitle, String prDescription, String mergeInto, String pullFrom, int milestoneId, String dueDate, List<String> assignees) {
|
||||
@ -170,8 +175,7 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
CreatePullRequest createPullRequest = new CreatePullRequest(prTitle, prDescription, loginUid, mergeInto, pullFrom, milestoneId, dueDate, assignees, labelsIds);
|
||||
|
||||
Call<ResponseBody> transferCall = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(appCtx)
|
||||
.createPullRequest(instanceToken, repoOwner, repoName, createPullRequest);
|
||||
|
||||
transferCall.enqueue(new Callback<ResponseBody>() {
|
||||
@ -201,7 +205,6 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.genericError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -231,6 +234,7 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
dialogLabels = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||
|
||||
if (dialogLabels.getWindow() != null) {
|
||||
|
||||
dialogLabels.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
}
|
||||
|
||||
@ -239,19 +243,17 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
View view = labelsBinding.getRoot();
|
||||
dialogLabels.setContentView(view);
|
||||
|
||||
labelsBinding.cancel.setOnClickListener(editProperties ->
|
||||
dialogLabels.dismiss()
|
||||
);
|
||||
labelsBinding.cancel.setOnClickListener(editProperties -> dialogLabels.dismiss());
|
||||
|
||||
LabelsActions.getRepositoryLabels(ctx, instanceUrl, instanceToken, repoOwner, repoName, labelsList, dialogLabels, labelsAdapter, labelsBinding);
|
||||
dialogLabels.show();
|
||||
LabelsActions.getRepositoryLabels(ctx, repoOwner, repoName, labelsList, dialogLabels, labelsAdapter, labelsBinding);
|
||||
}
|
||||
|
||||
private void getBranches(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid) {
|
||||
private void getBranches(String repoOwner, String repoName) {
|
||||
|
||||
Call<List<Branches>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getBranches(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
||||
.getApiInterface(ctx)
|
||||
.getBranches(Authorization.get(ctx), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<List<Branches>>() {
|
||||
|
||||
@ -259,19 +261,18 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull retrofit2.Response<List<Branches>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.code() == 200) {
|
||||
|
||||
List<Branches> branchesList_ = response.body();
|
||||
|
||||
assert branchesList_ != null;
|
||||
|
||||
if(branchesList_.size() > 0) {
|
||||
|
||||
for (int i = 0; i < branchesList_.size(); i++) {
|
||||
|
||||
Branches data = new Branches(
|
||||
branchesList_.get(i).getName()
|
||||
);
|
||||
Branches data = new Branches(branchesList_.get(i).getName());
|
||||
branchesList.add(data);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -296,13 +297,12 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
|
||||
}
|
||||
|
||||
private void getMilestones(String instanceUrl, String instanceToken, String repoOwner, String repoName, String loginUid, int resultLimit) {
|
||||
private void getMilestones(String repoOwner, String repoName, int resultLimit) {
|
||||
|
||||
String msState = "open";
|
||||
Call<List<Milestones>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getMilestones(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, 1, resultLimit, msState);
|
||||
.getApiInterface(appCtx)
|
||||
.getMilestones(Authorization.get(ctx), repoOwner, repoName, 1, resultLimit, msState);
|
||||
|
||||
call.enqueue(new Callback<List<Milestones>>() {
|
||||
|
||||
@ -315,7 +315,9 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
|
||||
milestonesList.add(new Milestones(0,getString(R.string.issueCreatedNoMilestone)));
|
||||
assert milestonesList_ != null;
|
||||
|
||||
if(milestonesList_.size() > 0) {
|
||||
|
||||
for (int i = 0; i < milestonesList_.size(); i++) {
|
||||
|
||||
//Don't translate "open" is a enum
|
||||
@ -326,7 +328,6 @@ public class CreatePullRequestActivity extends BaseActivity implements LabelsLis
|
||||
);
|
||||
milestonesList.add(data);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,24 +1,24 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
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;
|
||||
@ -36,14 +36,16 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
private View.OnClickListener onClickListener;
|
||||
public ImageView closeActivity;
|
||||
private EditText releaseTagName;
|
||||
private Spinner releaseBranch;
|
||||
private AutoCompleteTextView releaseBranch;
|
||||
private EditText releaseTitle;
|
||||
private EditText releaseContent;
|
||||
private CheckBox releaseType;
|
||||
private CheckBox releaseDraft;
|
||||
private Button createNewRelease;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private String selectedBranch;
|
||||
|
||||
private String repoOwner;
|
||||
private String repoName;
|
||||
|
||||
List<Branches> branchesList = new ArrayList<>();
|
||||
|
||||
@ -52,24 +54,20 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
return R.layout.activity_create_release;
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
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");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
repoOwner = parts[0];
|
||||
repoName = parts[1];
|
||||
|
||||
closeActivity = findViewById(R.id.close);
|
||||
releaseTagName = findViewById(R.id.releaseTagName);
|
||||
@ -78,26 +76,26 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
releaseType = findViewById(R.id.releaseType);
|
||||
releaseDraft = findViewById(R.id.releaseDraft);
|
||||
|
||||
releaseTagName.requestFocus();
|
||||
releaseTitle.requestFocus();
|
||||
assert imm != null;
|
||||
imm.showSoftInput(releaseTagName, InputMethodManager.SHOW_IMPLICIT);
|
||||
imm.showSoftInput(releaseTitle, InputMethodManager.SHOW_IMPLICIT);
|
||||
|
||||
releaseContent.setOnTouchListener((touchView, motionEvent) -> {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
|
||||
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
initCloseListener();
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
releaseBranch = findViewById(R.id.releaseBranch);
|
||||
getBranches(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
||||
releaseBranch.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
Branches branch = (Branches) parent.getSelectedItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
});
|
||||
getBranches(Authorization.get(ctx), repoOwner, repoName);
|
||||
|
||||
createNewRelease = findViewById(R.id.createNewRelease);
|
||||
disableProcessButton();
|
||||
@ -113,25 +111,16 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
private View.OnClickListener createReleaseListener = v -> processNewRelease();
|
||||
private final View.OnClickListener createReleaseListener = v -> processNewRelease();
|
||||
|
||||
private void processNewRelease() {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
|
||||
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];
|
||||
|
||||
String newReleaseTagName = releaseTagName.getText().toString();
|
||||
String newReleaseTitle = releaseTitle.getText().toString();
|
||||
String newReleaseContent = releaseContent.getText().toString();
|
||||
String newReleaseBranch = releaseBranch.getSelectedItem().toString();
|
||||
String checkBranch = selectedBranch;
|
||||
boolean newReleaseType = releaseType.isChecked();
|
||||
boolean newReleaseDraft = releaseDraft.isChecked();
|
||||
|
||||
@ -139,37 +128,38 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(newReleaseTitle.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.titleErrorEmpty));
|
||||
return;
|
||||
}
|
||||
|
||||
if(newReleaseTagName.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.tagNameErrorEmpty));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(newReleaseTitle.equals("")) {
|
||||
if(checkBranch == null) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.titleErrorEmpty));
|
||||
return;
|
||||
|
||||
}
|
||||
Toasty.error(ctx, getString(R.string.selectBranchError));
|
||||
return;
|
||||
}
|
||||
|
||||
disableProcessButton();
|
||||
createNewReleaseFunc(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, newReleaseTagName, newReleaseTitle, newReleaseContent, newReleaseBranch, newReleaseType, newReleaseDraft);
|
||||
|
||||
createNewReleaseFunc(Authorization.get(ctx), repoOwner, repoName, newReleaseTagName, newReleaseTitle, newReleaseContent, selectedBranch, newReleaseType, newReleaseDraft);
|
||||
}
|
||||
|
||||
private void createNewReleaseFunc(final String instanceUrl, final String token, String repoOwner, String repoName, String newReleaseTagName, String newReleaseTitle, String newReleaseContent, String newReleaseBranch, boolean newReleaseType, boolean newReleaseDraft) {
|
||||
private void createNewReleaseFunc(final String token, String repoOwner, String repoName, String newReleaseTagName, String newReleaseTitle, String newReleaseContent, String selectedBranch, boolean newReleaseType, boolean newReleaseDraft) {
|
||||
|
||||
Releases createReleaseJson = new Releases(newReleaseContent, newReleaseDraft, newReleaseTitle, newReleaseType, newReleaseTagName, newReleaseBranch);
|
||||
Releases createReleaseJson = new Releases(newReleaseContent, newReleaseDraft, newReleaseTitle, newReleaseType, newReleaseTagName, selectedBranch);
|
||||
|
||||
Call<Releases> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.createNewRelease(token, repoOwner, repoName, createReleaseJson);
|
||||
|
||||
call.enqueue(new Callback<Releases>() {
|
||||
@ -179,12 +169,10 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
|
||||
if (response.code() == 201) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
tinyDb.putBoolean("updateReleases", true);
|
||||
tinyDB.putBoolean("updateReleases", true);
|
||||
Toasty.success(ctx, getString(R.string.releaseCreatedText));
|
||||
enableProcessButton();
|
||||
finish();
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -193,31 +181,27 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
|
||||
}
|
||||
else if(response.code() == 404) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Releases> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
}
|
||||
@ -225,11 +209,10 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
private void getBranches(String instanceUrl, String instanceToken, final String repoOwner, final String repoName) {
|
||||
private void getBranches(String instanceToken, final String repoOwner, final String repoName) {
|
||||
|
||||
Call<List<Branches>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.getBranches(instanceToken, repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<List<Branches>>() {
|
||||
@ -238,29 +221,27 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
public void onResponse(@NonNull Call<List<Branches>> call, @NonNull retrofit2.Response<List<Branches>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
if(response.code() == 200) {
|
||||
|
||||
List<Branches> branchesList_ = response.body();
|
||||
|
||||
assert branchesList_ != null;
|
||||
if(branchesList_.size() > 0) {
|
||||
for (int i = 0; i < branchesList_.size(); i++) {
|
||||
|
||||
Branches data = new Branches(
|
||||
branchesList_.get(i).getName()
|
||||
);
|
||||
branchesList.add(data);
|
||||
|
||||
}
|
||||
branchesList.addAll(branchesList_);
|
||||
}
|
||||
|
||||
ArrayAdapter<Branches> adapter = new ArrayAdapter<>(CreateReleaseActivity.this,
|
||||
R.layout.spinner_item, branchesList);
|
||||
ArrayAdapter<Branches> adapter = new ArrayAdapter<>(CreateReleaseActivity.this,
|
||||
R.layout.list_spinner_items, branchesList);
|
||||
|
||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
||||
releaseBranch.setAdapter(adapter);
|
||||
enableProcessButton();
|
||||
|
||||
releaseBranch.setOnItemClickListener ((parent, view, position, id) ->
|
||||
|
||||
selectedBranch = branchesList.get(position).getName()
|
||||
);
|
||||
}
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
@ -269,13 +250,13 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Branches>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
}
|
||||
});
|
||||
@ -283,12 +264,8 @@ public class CreateReleaseActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
onClickListener = view -> finish();
|
||||
}
|
||||
|
||||
private void disableProcessButton() {
|
||||
|
@ -2,16 +2,17 @@ package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
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;
|
||||
@ -37,15 +38,18 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
|
||||
public ImageView closeActivity;
|
||||
private View.OnClickListener onClickListener;
|
||||
private Spinner spinner;
|
||||
private AutoCompleteTextView spinner;
|
||||
private Button createRepo;
|
||||
private EditText repoName;
|
||||
private EditText repoDesc;
|
||||
private CheckBox repoAccess;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
List<OrgOwner> organizationsList = new ArrayList<>();
|
||||
private String loginUid;
|
||||
private String userLogin;
|
||||
|
||||
private String selectedOwner;
|
||||
|
||||
List<OrgOwner> organizationsList = new ArrayList<>();
|
||||
|
||||
//https://github.com/go-gitea/gitea/blob/52cfd2743c0e85b36081cf80a850e6a5901f1865/models/repo.go#L964-L967
|
||||
final List<String> reservedRepoNames = Arrays.asList(".", "..");
|
||||
@ -60,15 +64,11 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(ctx);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String userLogin = tinyDb.getString("userLogin");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
loginUid = tinyDB.getString("loginUid");
|
||||
userLogin = tinyDB.getString("userLogin");
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
@ -85,19 +85,7 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
spinner = findViewById(R.id.ownerSpinner);
|
||||
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) {
|
||||
OrgOwner user = (OrgOwner) parent.getSelectedItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
});
|
||||
getOrganizations(Authorization.get(ctx), userLogin);
|
||||
|
||||
createRepo = findViewById(R.id.createNewRepoButton);
|
||||
disableProcessButton();
|
||||
@ -112,24 +100,15 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
private View.OnClickListener createRepoListener = new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
processNewRepo();
|
||||
}
|
||||
};
|
||||
private final View.OnClickListener createRepoListener = v -> processNewRepo();
|
||||
|
||||
private void processNewRepo() {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
AppUtil appUtil = new AppUtil();
|
||||
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 newRepoName = repoName.getText().toString();
|
||||
String newRepoDesc = repoDesc.getText().toString();
|
||||
String repoOwner = spinner.getSelectedItem().toString();
|
||||
boolean newRepoAccess = repoAccess.isChecked();
|
||||
|
||||
if(!connToInternet) {
|
||||
@ -139,6 +118,7 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if(!newRepoDesc.equals("")) {
|
||||
|
||||
if (appUtil.charactersLength(newRepoDesc) > 255) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.repoDescError));
|
||||
@ -161,32 +141,34 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
else if (reservedRepoPatterns.matcher(newRepoName).find()) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.repoNameErrorReservedPatterns));
|
||||
}
|
||||
else if(selectedOwner == null) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.repoOwnerError));
|
||||
}
|
||||
else {
|
||||
|
||||
disableProcessButton();
|
||||
createNewRepository(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), loginUid, newRepoName, newRepoDesc, repoOwner, newRepoAccess);
|
||||
createNewRepository(Authorization.get(ctx), loginUid, newRepoName, newRepoDesc, selectedOwner, newRepoAccess);
|
||||
}
|
||||
}
|
||||
|
||||
private void createNewRepository(final String instanceUrl, final String token, String loginUid, String repoName, String repoDesc, String repoOwner, boolean isPrivate) {
|
||||
private void createNewRepository(final String token, String loginUid, String repoName, String repoDesc, String selectedOwner, boolean isPrivate) {
|
||||
|
||||
OrganizationRepository createRepository = new OrganizationRepository(true, repoDesc, null, null, repoName, isPrivate, "Default");
|
||||
|
||||
Call<OrganizationRepository> call;
|
||||
if(repoOwner.equals(loginUid)) {
|
||||
if(selectedOwner.equals(loginUid)) {
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.createNewUserRepository(token, createRepository);
|
||||
}
|
||||
else {
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.createNewUserOrgRepository(token, repoOwner, createRepository);
|
||||
.getApiInterface(ctx)
|
||||
.createNewUserOrgRepository(token, selectedOwner, createRepository);
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<OrganizationRepository>() {
|
||||
@ -196,7 +178,7 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
|
||||
if(response.code() == 201) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
tinyDb.putBoolean("repoCreated", true);
|
||||
Toasty.success(ctx, getString(R.string.repoCreated));
|
||||
enableProcessButton();
|
||||
@ -220,7 +202,6 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.repoCreatedError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -232,13 +213,10 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private void getOrganizations(String instanceUrl, String instanceToken, final String userLogin) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
private void getOrganizations(String instanceToken, final String userLogin) {
|
||||
|
||||
Call<List<OrgOwner>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.getOrgOwners(instanceToken);
|
||||
|
||||
call.enqueue(new Callback<List<OrgOwner>>() {
|
||||
@ -246,59 +224,58 @@ public class CreateRepoActivity extends BaseActivity {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<OrgOwner>> call, @NonNull retrofit2.Response<List<OrgOwner>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
if(response.code() == 200) {
|
||||
if(response.code() == 200) {
|
||||
|
||||
int organizationId = 0;
|
||||
int organizationId = 0;
|
||||
|
||||
List<OrgOwner> organizationsList_ = response.body();
|
||||
List<OrgOwner> organizationsList_ = response.body();
|
||||
|
||||
organizationsList.add(new OrgOwner(userLogin));
|
||||
assert organizationsList_ != null;
|
||||
if(organizationsList_.size() > 0) {
|
||||
organizationsList.add(new OrgOwner(userLogin));
|
||||
assert organizationsList_ != null;
|
||||
|
||||
for (int i = 0; i < organizationsList_.size(); i++) {
|
||||
if(organizationsList_.size() > 0) {
|
||||
|
||||
if(!tinyDb.getString("organizationId").isEmpty()) {
|
||||
for(int i = 0; i < organizationsList_.size(); i++) {
|
||||
|
||||
if (Integer.parseInt(tinyDb.getString("organizationId")) == organizationsList_.get(i).getId()) {
|
||||
organizationId = i + 1;
|
||||
}
|
||||
}
|
||||
if(!tinyDB.getString("organizationId").isEmpty()) {
|
||||
|
||||
OrgOwner data = new OrgOwner(
|
||||
organizationsList_.get(i).getUsername()
|
||||
);
|
||||
organizationsList.add(data);
|
||||
if(Integer.parseInt(tinyDB.getString("organizationId")) == organizationsList_.get(i).getId()) {
|
||||
organizationId = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
OrgOwner data = new OrgOwner(organizationsList_.get(i).getUsername());
|
||||
organizationsList.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
ArrayAdapter<OrgOwner> adapter = new ArrayAdapter<>(CreateRepoActivity.this,
|
||||
R.layout.spinner_item, organizationsList);
|
||||
ArrayAdapter<OrgOwner> adapter = new ArrayAdapter<>(CreateRepoActivity.this, R.layout.list_spinner_items, organizationsList);
|
||||
|
||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
||||
spinner.setAdapter(adapter);
|
||||
spinner.setAdapter(adapter);
|
||||
|
||||
if (tinyDb.getBoolean("organizationAction") & organizationId != 0) {
|
||||
spinner.setOnItemClickListener ((parent, view, position, id) -> selectedOwner = organizationsList.get(position).getUsername());
|
||||
|
||||
spinner.setSelection(organizationId);
|
||||
tinyDb.putBoolean("organizationAction", false);
|
||||
}
|
||||
if(tinyDB.getBoolean("organizationAction") & organizationId != 0) {
|
||||
|
||||
enableProcessButton();
|
||||
int selectOwnerById = organizationId;
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
}
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
spinner.setText(organizationsList.get(selectOwnerById).getUsername(), false);
|
||||
selectedOwner = organizationsList.get(selectOwnerById).getUsername();
|
||||
}, 500);
|
||||
|
||||
enableProcessButton();
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
}
|
||||
tinyDB.putBoolean("organizationAction", false);
|
||||
}
|
||||
|
||||
enableProcessButton();
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,8 +31,6 @@ import retrofit2.Callback;
|
||||
|
||||
public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClickListener {
|
||||
|
||||
final Context ctx = CreateTeamByOrgActivity.this;
|
||||
private Context appCtx;
|
||||
private View.OnClickListener onClickListener;
|
||||
private TextView teamName;
|
||||
private TextView teamDesc;
|
||||
@ -41,7 +39,7 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
private TextView teamAccessControls;
|
||||
private TextView teamAccessControlsArray;
|
||||
private Button createTeamButton;
|
||||
private String[] permissionList = {"Read", "Write", "Admin"};
|
||||
private final String[] permissionList = {"Read", "Write", "Admin"};
|
||||
public int permissionSelectedChoice = -1;
|
||||
|
||||
@Override
|
||||
@ -49,7 +47,7 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
return R.layout.activity_create_team_by_org;
|
||||
}
|
||||
|
||||
private String[] accessControlsList = new String[] {
|
||||
private final String[] accessControlsList = new String[] {
|
||||
"Code",
|
||||
"Issues",
|
||||
"Pull Request",
|
||||
@ -61,7 +59,7 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
|
||||
private List<String> pushAccessList;
|
||||
|
||||
private boolean[] selectedAccessControlsTrueFalse = new boolean[]{
|
||||
private final boolean[] selectedAccessControlsTrueFalse = new boolean[]{
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
@ -75,7 +73,6 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
|
||||
@ -102,12 +99,8 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
AlertDialog.Builder pBuilder = new AlertDialog.Builder(ctx);
|
||||
|
||||
pBuilder.setTitle(R.string.newTeamPermission);
|
||||
if(permissionSelectedChoice != -1) {
|
||||
pBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
pBuilder.setCancelable(false);
|
||||
}
|
||||
pBuilder.setCancelable(permissionSelectedChoice != -1);
|
||||
|
||||
pBuilder.setSingleChoiceItems(permissionList, permissionSelectedChoice, (dialogInterface, i) -> {
|
||||
|
||||
permissionSelectedChoice = i;
|
||||
@ -136,15 +129,12 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
|
||||
dialogInterface.dismiss();
|
||||
|
||||
});
|
||||
|
||||
AlertDialog pDialog = pBuilder.create();
|
||||
pDialog.show();
|
||||
|
||||
});
|
||||
|
||||
|
||||
teamAccessControls.setOnClickListener(v -> {
|
||||
|
||||
teamAccessControls.setText("");
|
||||
@ -189,6 +179,7 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
}
|
||||
|
||||
if(value){
|
||||
|
||||
teamAccessControls.setText(getString(R.string.newTeamPermissionValues, teamAccessControls.getText(), pushAccessList.get(selectedVal)));
|
||||
teamAccessControlsArray.setText(getString(R.string.newTeamPermissionValuesFinal, teamAccessControlsArray.getText(), repoCode));
|
||||
}
|
||||
@ -198,15 +189,16 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
|
||||
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()));
|
||||
|
||||
});
|
||||
|
||||
AlertDialog aDialog = aDialogBuilder.create();
|
||||
@ -222,21 +214,18 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
shape.setCornerRadius( 8 );
|
||||
shape.setColor(getResources().getColor(R.color.hintColor));
|
||||
createTeamButton.setBackground(shape);
|
||||
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
createTeamButton.setEnabled(true);
|
||||
createTeamButton.setOnClickListener(this);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void processCreateTeam() {
|
||||
|
||||
AppUtil appUtil = new AppUtil();
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final String orgName = tinyDb.getString("orgName");;
|
||||
@ -251,64 +240,60 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (newTeamName.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.teamNameEmpty));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(!appUtil.checkStringsWithAlphaNumericDashDotUnderscore(newTeamName)) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.teamNameError));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(!newTeamDesc.equals("")) {
|
||||
|
||||
if(!appUtil.checkStrings(newTeamDesc)) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.teamDescError));
|
||||
return;
|
||||
}
|
||||
|
||||
if(newTeamDesc.length() > 100) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.teamDescLimit));
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (newTeamPermission.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.teamPermissionEmpty));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
List<String> newTeamAccessControls_ = new ArrayList<>(Arrays.asList(newTeamAccessControls.split(",")));
|
||||
|
||||
for (int i = 0; i < newTeamAccessControls_.size(); i++) {
|
||||
|
||||
newTeamAccessControls_.set(i, newTeamAccessControls_.get(i).trim());
|
||||
}
|
||||
|
||||
createNewTeamCall(instanceUrl, instanceToken, orgName, newTeamName, newTeamDesc, newTeamPermission, newTeamAccessControls_, loginUid);
|
||||
|
||||
createNewTeamCall(instanceToken, orgName, newTeamName, newTeamDesc, newTeamPermission, newTeamAccessControls_, loginUid);
|
||||
}
|
||||
|
||||
private void createNewTeamCall(final String instanceUrl, final String instanceToken, String orgName, String newTeamName, String newTeamDesc, String newTeamPermission, List<String> newTeamAccessControls, String loginUid) {
|
||||
private void createNewTeamCall(final String instanceToken, String orgName, String newTeamName, String newTeamDesc, String newTeamPermission, List<String> newTeamAccessControls, String loginUid) {
|
||||
|
||||
Teams createNewTeamJson = new Teams(newTeamName, newTeamDesc, newTeamPermission, newTeamAccessControls);
|
||||
|
||||
Call<Teams> call3;
|
||||
|
||||
call3 = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.createTeamsByOrg(Authorization.returnAuthentication(ctx, loginUid, instanceToken), orgName, createNewTeamJson);
|
||||
.getApiInterface(ctx)
|
||||
.createTeamsByOrg(Authorization.get(ctx), orgName, createNewTeamJson);
|
||||
|
||||
call3.enqueue(new Callback<Teams>() {
|
||||
|
||||
@ -316,15 +301,15 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
public void onResponse(@NonNull Call<Teams> call, @NonNull retrofit2.Response<Teams> response2) {
|
||||
|
||||
if(response2.isSuccessful()) {
|
||||
|
||||
if(response2.code() == 201) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
tinyDb.putBoolean("resumeTeams", true);
|
||||
|
||||
Toasty.success(ctx, getString(R.string.teamCreated));
|
||||
finish();
|
||||
}
|
||||
|
||||
}
|
||||
else if(response2.code() == 404) {
|
||||
|
||||
@ -341,7 +326,6 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
|
||||
Toasty.error(ctx, getString(R.string.teamCreatedError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -356,6 +340,7 @@ public class CreateTeamByOrgActivity extends BaseActivity implements View.OnClic
|
||||
public void onClick(View v) {
|
||||
|
||||
if(v == createTeamButton) {
|
||||
|
||||
processCreateTeam();
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,455 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import androidx.annotation.NonNull;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||
import org.mian.gitnex.database.api.UserAccountsApi;
|
||||
import org.mian.gitnex.database.models.Repository;
|
||||
import org.mian.gitnex.database.models.UserAccount;
|
||||
import org.mian.gitnex.databinding.ActivityDeeplinksBinding;
|
||||
import org.mian.gitnex.helpers.UrlHelper;
|
||||
import org.mian.gitnex.models.PullRequests;
|
||||
import org.mian.gitnex.models.UserRepositories;
|
||||
import java.net.URI;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import io.mikael.urlbuilder.UrlBuilder;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class DeepLinksActivity extends BaseActivity {
|
||||
|
||||
private ActivityDeeplinksBinding viewBinding;
|
||||
private String currentInstance;
|
||||
private String instanceToken;
|
||||
private boolean accountFound = false;
|
||||
|
||||
private Intent mainIntent;
|
||||
private Intent issueIntent;
|
||||
private Intent repoIntent;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId() {
|
||||
|
||||
return R.layout.activity_deeplinks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
viewBinding = ActivityDeeplinksBinding.inflate(getLayoutInflater());
|
||||
View view = viewBinding.getRoot();
|
||||
setContentView(view);
|
||||
|
||||
mainIntent = new Intent(ctx, MainActivity.class);
|
||||
issueIntent = new Intent(ctx, IssueDetailActivity.class);
|
||||
repoIntent = new Intent(ctx, RepoDetailActivity.class);
|
||||
|
||||
Intent intent = getIntent();
|
||||
Uri data = intent.getData();
|
||||
assert data != null;
|
||||
|
||||
// check for login
|
||||
if(!tinyDB.getBoolean("loggedInMode")) {
|
||||
|
||||
finish();
|
||||
ctx.startActivity(new Intent(ctx, LoginActivity.class));
|
||||
}
|
||||
|
||||
// check for the links(URI) to be in the db
|
||||
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
||||
List<UserAccount> userAccounts = userAccountsApi.usersAccounts();
|
||||
|
||||
for(UserAccount userAccount : userAccounts) {
|
||||
|
||||
String hostUri = userAccount.getInstanceUrl();
|
||||
|
||||
currentInstance = userAccount.getInstanceUrl();
|
||||
instanceToken = userAccount.getToken();
|
||||
|
||||
if(hostUri.toLowerCase().contains(Objects.requireNonNull(data.getHost().toLowerCase()))) {
|
||||
|
||||
accountFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(accountFound) {
|
||||
|
||||
// redirect to proper fragment/activity, If no action is there, show options where user to want to go like repos, profile, notifications etc
|
||||
if(data.getPathSegments().size() > 0) {
|
||||
|
||||
viewBinding.progressBar.setVisibility(View.GONE);
|
||||
String[] restOfUrl = Objects.requireNonNull(data.getPath()).split("/");
|
||||
|
||||
if(data.getPathSegments().contains("issues")) { // issue
|
||||
|
||||
if(!Objects.requireNonNull(data.getLastPathSegment()).contains("issues") & StringUtils.isNumeric(data.getLastPathSegment())) {
|
||||
|
||||
issueIntent.putExtra("issueNumber", data.getLastPathSegment());
|
||||
|
||||
tinyDB.putString("issueNumber", data.getLastPathSegment());
|
||||
tinyDB.putString("issueType", "Issue");
|
||||
|
||||
tinyDB.putString("repoFullName", restOfUrl[restOfUrl.length - 4] + "/" + restOfUrl[restOfUrl.length - 3]);
|
||||
|
||||
final String repoOwner = restOfUrl[restOfUrl.length - 4];
|
||||
final String repoName = restOfUrl[restOfUrl.length - 3];
|
||||
|
||||
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = new RepositoriesApi(ctx);
|
||||
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
|
||||
if(count == 0) {
|
||||
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
tinyDB.putLong("repositoryId", id);
|
||||
}
|
||||
else {
|
||||
|
||||
Repository dataRepo = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
tinyDB.putLong("repositoryId", dataRepo.getRepositoryId());
|
||||
}
|
||||
|
||||
ctx.startActivity(issueIntent);
|
||||
finish();
|
||||
}
|
||||
else if(Objects.requireNonNull(data.getLastPathSegment()).contains("issues")) {
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
goToRepoSection(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 3], restOfUrl[restOfUrl.length - 2], "issue");
|
||||
}, 500);
|
||||
}
|
||||
else {
|
||||
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
else if(data.getPathSegments().contains("pulls")) { // pr
|
||||
|
||||
if(!Objects.requireNonNull(data.getLastPathSegment()).contains("pulls") & StringUtils.isNumeric(data.getLastPathSegment())) {
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
getPullRequest(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 4], restOfUrl[restOfUrl.length - 3], Integer.parseInt(data.getLastPathSegment()));
|
||||
}, 500);
|
||||
|
||||
}
|
||||
else if(Objects.requireNonNull(data.getLastPathSegment()).contains("pulls")) {
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
goToRepoSection(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 3], restOfUrl[restOfUrl.length - 2], "pull");
|
||||
}, 500);
|
||||
}
|
||||
else {
|
||||
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
else if(data.getPathSegments().contains("commit")) { // commits (no API yet to properly implement)
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
goToRepoSection(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 4], restOfUrl[restOfUrl.length - 3], "pull");
|
||||
}, 500);
|
||||
}
|
||||
else if(!restOfUrl[restOfUrl.length - 2].equals("") & !restOfUrl[restOfUrl.length - 1].equals("")) { // go to repo
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
goToRepoSection(currentInstance, instanceToken, restOfUrl[restOfUrl.length - 2], restOfUrl[restOfUrl.length - 1], "repo");
|
||||
}, 500);
|
||||
}
|
||||
else { // no action, show options
|
||||
|
||||
if(tinyDB.getInt("defaultScreenId") == 1) { // repos
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 2) { // org
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 3) { // notifications
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 4) { // explore
|
||||
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
else if(tinyDB.getInt("defaultScreenId") == 0) { // show options
|
||||
|
||||
viewBinding.noActionFrame.setVisibility(View.VISIBLE);
|
||||
viewBinding.addNewAccountFrame.setVisibility(View.GONE);
|
||||
|
||||
viewBinding.repository.setOnClickListener(repository -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 1);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "repos");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.organization.setOnClickListener(organization -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 2);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "org");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.notification.setOnClickListener(notification -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 3);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "notification");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.explore.setOnClickListener(explore -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 4);
|
||||
mainIntent.putExtra("launchFragmentByLinkHandler", "explore");
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.launchApp2.setOnClickListener(launchApp2 -> {
|
||||
|
||||
tinyDB.putInt("defaultScreenId", 0);
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
viewBinding.progressBar.setVisibility(View.GONE);
|
||||
viewBinding.addNewAccountFrame.setVisibility(View.VISIBLE);
|
||||
viewBinding.noActionFrame.setVisibility(View.GONE);
|
||||
viewBinding.addAccountText.setText(String.format(getResources().getString(R.string.accountDoesNotExist), data.getHost()));
|
||||
|
||||
viewBinding.addNewAccount.setOnClickListener(addNewAccount -> {
|
||||
|
||||
Intent accountIntent = new Intent(ctx, AddNewAccountActivity.class);
|
||||
startActivity(accountIntent);
|
||||
finish();
|
||||
});
|
||||
|
||||
viewBinding.openInBrowser.setOnClickListener(addNewAccount -> {
|
||||
|
||||
Integer port = data.getPort() >= 0 ? data.getPort() : null;
|
||||
|
||||
URI host = UrlBuilder.fromString(UrlHelper.fixScheme(data.getHost(), "https"))
|
||||
.withPort(port)
|
||||
.toUri();
|
||||
|
||||
Intent intentBrowser = new Intent();
|
||||
|
||||
intentBrowser.setAction(Intent.ACTION_VIEW);
|
||||
intentBrowser.addCategory(Intent.CATEGORY_BROWSABLE);
|
||||
intentBrowser.setData(Uri.parse(String.valueOf(host)));
|
||||
|
||||
startActivity(intentBrowser);
|
||||
finish();
|
||||
|
||||
});
|
||||
|
||||
viewBinding.launchApp.setOnClickListener(launchApp -> {
|
||||
|
||||
startActivity(mainIntent);
|
||||
finish();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void getPullRequest(String url, String token, String repoOwner, String repoName, int index) {
|
||||
|
||||
Call<PullRequests> call = RetrofitClient
|
||||
.getApiInterface(ctx, url)
|
||||
.getPullRequestByIndex(token, repoOwner, repoName, index);
|
||||
|
||||
call.enqueue(new Callback<PullRequests>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<PullRequests> call, @NonNull retrofit2.Response<PullRequests> response) {
|
||||
|
||||
PullRequests prInfo = response.body();
|
||||
|
||||
if (response.code() == 200) {
|
||||
|
||||
assert prInfo != null;
|
||||
|
||||
issueIntent.putExtra("issueNumber", index);
|
||||
issueIntent.putExtra("prMergeable", prInfo.isMergeable());
|
||||
|
||||
if(prInfo.getHead() != null) {
|
||||
|
||||
issueIntent.putExtra("prHeadBranch", prInfo.getHead().getRef());
|
||||
tinyDB.putString("prHeadBranch", prInfo.getHead().getRef());
|
||||
|
||||
if(prInfo.getHead().getRepo() != null) {
|
||||
|
||||
tinyDB.putString("prIsFork", String.valueOf(prInfo.getHead().getRepo().isFork()));
|
||||
tinyDB.putString("prForkFullName", prInfo.getHead().getRepo().getFull_name());
|
||||
}
|
||||
else {
|
||||
|
||||
// pull was done from a deleted fork
|
||||
tinyDB.putString("prIsFork", "true");
|
||||
tinyDB.putString("prForkFullName", ctx.getString(R.string.prDeletedFrok));
|
||||
}
|
||||
}
|
||||
|
||||
tinyDB.putString("issueNumber", String.valueOf(index));
|
||||
tinyDB.putString("prMergeable", String.valueOf(prInfo.isMergeable()));
|
||||
tinyDB.putString("issueType", "Pull");
|
||||
|
||||
tinyDB.putString("repoFullName", repoOwner + "/" + repoName);
|
||||
|
||||
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = new RepositoriesApi(ctx);
|
||||
|
||||
Integer count = repositoryData.checkRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
|
||||
if(count == 0) {
|
||||
|
||||
long id = repositoryData.insertRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
tinyDB.putLong("repositoryId", id);
|
||||
}
|
||||
else {
|
||||
|
||||
Repository dataRepo = repositoryData.getRepository(currentActiveAccountId, repoOwner, repoName);
|
||||
tinyDB.putLong("repositoryId", dataRepo.getRepositoryId());
|
||||
}
|
||||
|
||||
ctx.startActivity(issueIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
ctx.startActivity(issueIntent);
|
||||
finish();
|
||||
Log.e("onFailure-links-pr", String.valueOf(response.code()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<PullRequests> call, @NonNull Throwable t) {
|
||||
|
||||
ctx.startActivity(issueIntent);
|
||||
finish();
|
||||
Log.e("onFailure-links-pr", t.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void goToRepoSection(String url, String token, String repoOwner, String repoName, String type) {
|
||||
|
||||
Call<UserRepositories> call = RetrofitClient
|
||||
.getApiInterface(ctx, url)
|
||||
.getUserRepository(token, repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<UserRepositories>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<UserRepositories> call, @NonNull retrofit2.Response<UserRepositories> response) {
|
||||
|
||||
UserRepositories repoInfo = response.body();
|
||||
|
||||
if (response.code() == 200) {
|
||||
|
||||
assert repoInfo != null;
|
||||
|
||||
repoIntent.putExtra("repoFullName", repoInfo.getFullName());
|
||||
repoIntent.putExtra("goToSection", "yes");
|
||||
repoIntent.putExtra("goToSectionType", type);
|
||||
|
||||
tinyDB.putString("repoFullName", repoInfo.getFullName());
|
||||
if(repoInfo.getPrivateFlag()) {
|
||||
|
||||
tinyDB.putString("repoType", getResources().getString(R.string.strPrivate));
|
||||
}
|
||||
else {
|
||||
|
||||
tinyDB.putString("repoType", getResources().getString(R.string.strPublic));
|
||||
}
|
||||
tinyDB.putBoolean("isRepoAdmin", repoInfo.getPermissions().isAdmin());
|
||||
tinyDB.putString("repoBranch", repoInfo.getDefault_branch());
|
||||
|
||||
int currentActiveAccountId = tinyDB.getInt("currentActiveAccountId");
|
||||
RepositoriesApi repositoryData = new RepositoriesApi(ctx);
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
ctx.startActivity(repoIntent);
|
||||
finish();
|
||||
}
|
||||
|
||||
else {
|
||||
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
Log.e("onFailure-goToRepo", String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<UserRepositories> call, @NonNull Throwable t) {
|
||||
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
Log.e("onFailure-goToRepo", t.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -4,31 +4,28 @@ import android.annotation.SuppressLint;
|
||||
import android.app.DatePickerDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.DatePicker;
|
||||
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;
|
||||
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;
|
||||
@ -39,7 +36,6 @@ import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -47,45 +43,46 @@ import retrofit2.Response;
|
||||
|
||||
public class EditIssueActivity extends BaseActivity implements View.OnClickListener {
|
||||
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private View.OnClickListener onClickListener;
|
||||
private int resultLimit = StaticGlobalVariables.resultLimitOldGiteaInstances;
|
||||
|
||||
private EditText editIssueTitle;
|
||||
private SocialAutoCompleteTextView editIssueDescription;
|
||||
private EditText editIssueDescription;
|
||||
private TextView editIssueDueDate;
|
||||
private Button editIssueButton;
|
||||
private Spinner editIssueMilestoneSpinner;
|
||||
private AutoCompleteTextView editIssueMilestoneSpinner;
|
||||
|
||||
private String msState = "open";
|
||||
private int milestoneId;
|
||||
|
||||
List<Milestones> milestonesList = new ArrayList<>();
|
||||
private ArrayAdapter<Mention> defaultMentionAdapter;
|
||||
|
||||
private String loginUid;
|
||||
private String instanceToken;
|
||||
private String repoOwner;
|
||||
private String repoName;
|
||||
private int issueIndex;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_edit_issue;
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
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");
|
||||
loginUid = tinyDB.getString("loginUid");
|
||||
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"));
|
||||
repoOwner = parts[0];
|
||||
repoName = parts[1];
|
||||
issueIndex = Integer.parseInt(tinyDB.getString("issueNumber"));
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
editIssueButton = findViewById(R.id.editIssueButton);
|
||||
@ -95,7 +92,8 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
editIssueDueDate = findViewById(R.id.editIssueDueDate);
|
||||
|
||||
// if gitea is 1.12 or higher use the new limit
|
||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
|
||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
||||
}
|
||||
|
||||
@ -103,110 +101,49 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
assert imm != null;
|
||||
imm.showSoftInput(editIssueTitle, InputMethodManager.SHOW_IMPLICIT);
|
||||
|
||||
defaultMentionAdapter = new MentionArrayAdapter<>(this);
|
||||
loadCollaboratorsList();
|
||||
editIssueDescription.setOnTouchListener((touchView, motionEvent) -> {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(true);
|
||||
|
||||
if ((motionEvent.getAction() & MotionEvent.ACTION_UP) != 0 && (motionEvent.getActionMasked() & MotionEvent.ACTION_UP) != 0) {
|
||||
|
||||
touchView.getParent().requestDisallowInterceptTouchEvent(false);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
editIssueMilestoneSpinner = findViewById(R.id.editIssueMilestoneSpinner);
|
||||
|
||||
editIssueDescription.setMentionAdapter(defaultMentionAdapter);
|
||||
|
||||
initCloseListener();
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
editIssueDueDate.setOnClickListener(this);
|
||||
editIssueButton.setOnClickListener(this);
|
||||
|
||||
if(!tinyDb.getString("issueNumber").isEmpty()) {
|
||||
if(!tinyDB.getString("issueNumber").isEmpty()) {
|
||||
|
||||
if(tinyDB.getString("issueType").equalsIgnoreCase("Pull")) {
|
||||
|
||||
if(tinyDb.getString("issueType").equalsIgnoreCase("Pull")) {
|
||||
toolbar_title.setText(getString(R.string.editPrNavHeader, String.valueOf(issueIndex)));
|
||||
}
|
||||
else {
|
||||
|
||||
toolbar_title.setText(getString(R.string.editIssueNavHeader, String.valueOf(issueIndex)));
|
||||
}
|
||||
}
|
||||
|
||||
disableProcessButton();
|
||||
getIssue(instanceUrl, instanceToken, loginUid, repoOwner, repoName, issueIndex, resultLimit);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void loadCollaboratorsList() {
|
||||
|
||||
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];
|
||||
|
||||
Call<List<Collaborators>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<List<Collaborators>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
||||
Log.i("onFailure", t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
getIssue(instanceToken, loginUid, repoOwner, repoName, issueIndex, resultLimit);
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
};
|
||||
|
||||
onClickListener = view -> finish();
|
||||
}
|
||||
|
||||
private void processEditIssue() {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final int issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
||||
|
||||
Milestones mModel = (Milestones) editIssueMilestoneSpinner.getSelectedItem();
|
||||
|
||||
int editIssueMilestoneId = mModel.getId();
|
||||
|
||||
String editIssueTitleForm = editIssueTitle.getText().toString();
|
||||
String editIssueDescriptionForm = editIssueDescription.getText().toString();
|
||||
@ -216,45 +153,34 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if (editIssueTitleForm.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.issueTitleEmpty));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/*if (editIssueDescriptionForm.equals("")) {
|
||||
|
||||
Toasty.info(ctx, getString(R.string.issueDescriptionEmpty));
|
||||
return;
|
||||
|
||||
}*/
|
||||
|
||||
if (editIssueDueDateForm.equals("")) {
|
||||
|
||||
editIssueDueDateForm = null;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
editIssueDueDateForm = (AppUtil.customDateCombine(AppUtil.customDateFormat(editIssueDueDateForm)));
|
||||
}
|
||||
|
||||
//Log.i("editIssueDueDateForm", String.valueOf(editIssueDueDateForm));
|
||||
disableProcessButton();
|
||||
editIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid, editIssueTitleForm, editIssueDescriptionForm, editIssueDueDateForm, editIssueMilestoneId);
|
||||
|
||||
editIssue(instanceToken, repoOwner, repoName, issueIndex, loginUid, editIssueTitleForm, editIssueDescriptionForm, editIssueDueDateForm, milestoneId);
|
||||
}
|
||||
|
||||
private void editIssue(String instanceUrl, String instanceToken, String repoOwner, String repoName, int issueIndex, String loginUid, String title, String description, String dueDate, int editIssueMilestoneId) {
|
||||
private void editIssue(String instanceToken, String repoOwner, String repoName, int issueIndex, String loginUid, String title, String description, String dueDate, int milestoneId) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
CreateIssue issueData = new CreateIssue(title, description, dueDate, editIssueMilestoneId);
|
||||
CreateIssue issueData = new CreateIssue(title, description, dueDate, milestoneId);
|
||||
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.patchIssue(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, issueData);
|
||||
.getApiInterface(ctx)
|
||||
.patchIssue(Authorization.get(ctx), repoOwner, repoName, issueIndex, issueData);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -263,17 +189,18 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
|
||||
if(response.code() == 201) {
|
||||
|
||||
if(tinyDb.getString("issueType").equalsIgnoreCase("Pull")) {
|
||||
if(tinyDB.getString("issueType").equalsIgnoreCase("Pull")) {
|
||||
|
||||
Toasty.success(ctx, getString(R.string.editPrSuccessMessage));
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.success(ctx, getString(R.string.editIssueSuccessMessage));
|
||||
}
|
||||
|
||||
tinyDb.putBoolean("issueEdited", true);
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
tinyDB.putBoolean("issueEdited", true);
|
||||
tinyDB.putBoolean("resumeIssues", true);
|
||||
finish();
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -282,19 +209,17 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.genericError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
}
|
||||
@ -302,7 +227,6 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
@ -314,31 +238,21 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
final int mDay = c.get(Calendar.DAY_OF_MONTH);
|
||||
|
||||
DatePickerDialog datePickerDialog = new DatePickerDialog(this,
|
||||
new DatePickerDialog.OnDateSetListener() {
|
||||
|
||||
@Override
|
||||
public void onDateSet(DatePicker view, int year,
|
||||
int monthOfYear, int dayOfMonth) {
|
||||
|
||||
editIssueDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth));
|
||||
|
||||
}
|
||||
}, mYear, mMonth, mDay);
|
||||
(view, year, monthOfYear, dayOfMonth) -> editIssueDueDate.setText(getString(R.string.setDueDate, year, (monthOfYear + 1), dayOfMonth)), mYear, mMonth, mDay);
|
||||
datePickerDialog.show();
|
||||
|
||||
}
|
||||
else if(v == editIssueButton) {
|
||||
|
||||
processEditIssue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void getIssue(final String instanceUrl, final String instanceToken, final String loginUid, final String repoOwner, final String repoName, int issueIndex, int resultLimit) {
|
||||
private void getIssue(final String instanceToken, final String loginUid, final String repoOwner, final String repoName, int issueIndex, int resultLimit) {
|
||||
|
||||
Call<Issues> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
||||
.getApiInterface(ctx)
|
||||
.getIssueByIndex(Authorization.get(ctx), repoOwner, repoName, issueIndex);
|
||||
|
||||
call.enqueue(new Callback<Issues>() {
|
||||
|
||||
@ -351,27 +265,27 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
editIssueTitle.setText(response.body().getTitle());
|
||||
editIssueDescription.setText(response.body().getBody());
|
||||
|
||||
int msId = 0;
|
||||
int currentMilestoneId = 0;
|
||||
if(response.body().getMilestone() != null) {
|
||||
msId = response.body().getMilestone().getId();
|
||||
|
||||
currentMilestoneId = response.body().getMilestone().getId();
|
||||
}
|
||||
|
||||
// get milestones list
|
||||
if(response.body().getId() > 0) {
|
||||
|
||||
Call<List<Milestones>> call_ = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getMilestones(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, 1, resultLimit, msState);
|
||||
.getApiInterface(ctx)
|
||||
.getMilestones(Authorization.get(ctx), repoOwner, repoName, 1, resultLimit, msState);
|
||||
|
||||
final int finalMsId = msId;
|
||||
int checkMilestoneId = currentMilestoneId;
|
||||
|
||||
call_.enqueue(new Callback<List<Milestones>>() {
|
||||
call_.enqueue(new Callback<List<Milestones>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Milestones>> call, @NonNull retrofit2.Response<List<Milestones>> response_) {
|
||||
|
||||
int finalMsId1 = 0;
|
||||
int getSelectedMilestoneId = 0;
|
||||
|
||||
if (response_.code() == 200) {
|
||||
|
||||
@ -379,39 +293,40 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
|
||||
milestonesList.add(new Milestones(0, "No milestone"));
|
||||
assert milestonesList_ != null;
|
||||
|
||||
if (milestonesList_.size() > 0) {
|
||||
|
||||
milestonesList.addAll(milestonesList_);
|
||||
|
||||
for (int i = 0; i < milestonesList_.size(); i++) {
|
||||
|
||||
Milestones data = new Milestones(
|
||||
milestonesList_.get(i).getId(),
|
||||
milestonesList_.get(i).getTitle()
|
||||
);
|
||||
milestonesList.add(data);
|
||||
|
||||
if(finalMsId == milestonesList_.get(i).getId()) {
|
||||
finalMsId1 = i + 1;
|
||||
if(checkMilestoneId == milestonesList_.get(i).getId()) {
|
||||
getSelectedMilestoneId = i + 1;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
ArrayAdapter<Milestones> adapter_ = new ArrayAdapter<>(EditIssueActivity.this,
|
||||
R.layout.spinner_item, milestonesList);
|
||||
ArrayAdapter<Milestones> adapter = new ArrayAdapter<>(EditIssueActivity.this,
|
||||
R.layout.list_spinner_items, milestonesList);
|
||||
|
||||
adapter_.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
||||
editIssueMilestoneSpinner.setAdapter(adapter_);
|
||||
editIssueMilestoneSpinner.setAdapter(adapter);
|
||||
|
||||
editIssueMilestoneSpinner.setOnItemClickListener ((parent, view, position, id) -> milestoneId = milestonesList.get(position).getId());
|
||||
|
||||
int finalMsId = getSelectedMilestoneId;
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
editIssueMilestoneSpinner.setText(milestonesList.get(finalMsId).getTitle(),false);
|
||||
milestoneId = milestonesList.get(finalMsId).getId();
|
||||
}, 500);
|
||||
|
||||
if(milestonesList_.size() > 0) {
|
||||
editIssueMilestoneSpinner.setSelection(finalMsId1);
|
||||
}
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Milestones>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
}
|
||||
});
|
||||
@ -439,11 +354,11 @@ public class EditIssueActivity extends BaseActivity implements View.OnClickListe
|
||||
|
||||
Toasty.error(ctx, getString(R.string.genericError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<Issues> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
}
|
||||
});
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
@ -14,7 +13,6 @@ 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;
|
||||
@ -36,8 +34,6 @@ public class FileDiffActivity extends BaseActivity {
|
||||
private TextView toolbarTitle;
|
||||
private ListView mListView;
|
||||
private ProgressBar mProgressBar;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId() {
|
||||
@ -49,12 +45,11 @@ public class FileDiffActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
@ -77,28 +72,21 @@ public class FileDiffActivity extends BaseActivity {
|
||||
|
||||
String pullIndex = tinyDb.getString("issueNumber");
|
||||
|
||||
boolean apiCall = true;
|
||||
String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
|
||||
// fallback for old gitea instances
|
||||
if(new Version(tinyDb.getString("giteaVersion")).less("1.13.0")) {
|
||||
|
||||
apiCall = false;
|
||||
instanceUrl = instanceUrl.substring(0, instanceUrl.lastIndexOf("api/v1/"));
|
||||
}
|
||||
|
||||
getPullDiffContent(instanceUrl, repoOwner, repoName, pullIndex, instanceToken, apiCall);
|
||||
boolean apiCall = !new Version(tinyDb.getString("giteaVersion")).less("1.13.0");
|
||||
getPullDiffContent(repoOwner, repoName, pullIndex, instanceToken, apiCall);
|
||||
|
||||
}
|
||||
|
||||
private void getPullDiffContent(String instanceUrl, String owner, String repo, String pullIndex, String token, boolean apiCall) {
|
||||
private void getPullDiffContent(String owner, String repo, String pullIndex, String token, boolean apiCall) {
|
||||
|
||||
Call<ResponseBody> call;
|
||||
if(apiCall) {
|
||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getPullDiffContent(token, owner, repo, pullIndex);
|
||||
|
||||
call = RetrofitClient.getApiInterface(ctx).getPullDiffContent(token, owner, repo, pullIndex);
|
||||
}
|
||||
else {
|
||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getWebInterface().getPullDiffContent(owner, repo, pullIndex);
|
||||
|
||||
call = RetrofitClient.getWebInterface(ctx).getPullDiffContent(owner, repo, pullIndex);
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<ResponseBody>() {
|
||||
@ -109,16 +97,18 @@ public class FileDiffActivity extends BaseActivity {
|
||||
if(response.code() == 200) {
|
||||
|
||||
try {
|
||||
|
||||
assert response.body() != null;
|
||||
|
||||
AppUtil appUtil = new AppUtil();
|
||||
List<FileDiffView> fileContentsArray = ParseDiff.getFileDiffViewArray(response.body().string());
|
||||
|
||||
int filesCount = fileContentsArray.size();
|
||||
if(filesCount > 1) {
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.fileDiffViewHeader, Integer.toString(filesCount)));
|
||||
}
|
||||
else {
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.fileDiffViewHeaderSingle, Integer.toString(filesCount)));
|
||||
}
|
||||
|
||||
@ -126,34 +116,28 @@ public class FileDiffActivity extends BaseActivity {
|
||||
mListView.setAdapter(adapter);
|
||||
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
catch(IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
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));
|
||||
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
|
||||
}
|
||||
else if(response.code() == 404) {
|
||||
|
||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -174,5 +158,4 @@ public class FileDiffActivity extends BaseActivity {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Typeface;
|
||||
@ -8,7 +8,6 @@ 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;
|
||||
@ -21,8 +20,11 @@ import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import androidx.activity.result.ActivityResult;
|
||||
import androidx.activity.result.ActivityResultCallback;
|
||||
import androidx.activity.result.ActivityResultLauncher;
|
||||
import androidx.activity.result.contract.ActivityResultContracts;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import com.github.barteksc.pdfviewer.PDFView;
|
||||
import com.github.barteksc.pdfviewer.util.FitPolicy;
|
||||
@ -33,7 +35,7 @@ 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.Markdown;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.highlightjs.HighlightJsView;
|
||||
import org.mian.gitnex.helpers.highlightjs.models.Theme;
|
||||
@ -43,24 +45,7 @@ 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;
|
||||
|
||||
@ -75,8 +60,6 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
private LinearLayout singleFileContentsFrame;
|
||||
private HighlightJsView singleCodeContents;
|
||||
private PhotoView imageView;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private ProgressBar mProgressBar;
|
||||
private byte[] imageData;
|
||||
private PDFView pdfView;
|
||||
@ -86,7 +69,6 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
private String singleFileName;
|
||||
private String fileSha;
|
||||
private AppUtil appUtil;
|
||||
private TinyDB tinyDb;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId() {
|
||||
@ -98,23 +80,20 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
appUtil = new AppUtil();
|
||||
tinyDb = new TinyDB(appCtx);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String repoBranch = tinyDb.getString("repoBranch");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String repoBranch = tinyDB.getString("repoBranch");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
final String loginUid = tinyDB.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||
|
||||
tinyDb.putBoolean("enableMarkdownInFileView", false);
|
||||
tinyDB.putBoolean("enableMarkdownInFileView", false);
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
singleFileContents = findViewById(R.id.singleFileContents);
|
||||
@ -133,25 +112,22 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
initCloseListener();
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
tinyDb.putString("downloadFileContents", "");
|
||||
tinyDB.putString("downloadFileContents", "");
|
||||
|
||||
try {
|
||||
|
||||
singleFileName = URLDecoder.decode(singleFileName, "UTF-8");
|
||||
singleFileName = singleFileName.replaceAll("//", "/");
|
||||
singleFileName = singleFileName.startsWith("/") ? singleFileName.substring(1) : singleFileName;
|
||||
|
||||
}
|
||||
catch(UnsupportedEncodingException e) {
|
||||
|
||||
Log.i("singleFileName", singleFileName);
|
||||
|
||||
}
|
||||
|
||||
toolbar_title.setText(singleFileName);
|
||||
|
||||
getSingleFileContents(instanceUrl, instanceToken, repoOwner, repoName, singleFileName, repoBranch);
|
||||
|
||||
getSingleFileContents(instanceToken, repoOwner, repoName, singleFileName, repoBranch);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -159,25 +135,25 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
|
||||
super.onResume();
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String repoBranch = tinyDb.getString("repoBranch");
|
||||
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");
|
||||
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);
|
||||
if(tinyDB.getBoolean("fileModified")) {
|
||||
|
||||
getSingleFileContents(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) {
|
||||
private void getSingleFileContents(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<Files> call = RetrofitClient.getApiInterface(ctx).getSingleFileContents(token, owner, repo, filename, ref);
|
||||
|
||||
call.enqueue(new Callback<Files>() {
|
||||
|
||||
@ -196,8 +172,8 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
fileSha = response.body().getSha();
|
||||
|
||||
// download file meta
|
||||
tinyDb.putString("downloadFileName", filename);
|
||||
tinyDb.putString("downloadFileContents", response.body().getContent());
|
||||
tinyDB.putString("downloadFileName", filename);
|
||||
tinyDB.putString("downloadFileContents", response.body().getContent());
|
||||
|
||||
if(appUtil.imageExtension(fileExtension)) { // file is image
|
||||
|
||||
@ -209,7 +185,6 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
imageData = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
||||
Drawable imageDrawable = new BitmapDrawable(getResources(), BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
|
||||
imageView.setImageDrawable(imageDrawable);
|
||||
|
||||
}
|
||||
else if(appUtil.sourceCodeExtension(fileExtension)) { // file is sourcecode
|
||||
|
||||
@ -218,28 +193,34 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
pdfViewFrame.setVisibility(View.GONE);
|
||||
singleCodeContents.setVisibility(View.VISIBLE);
|
||||
|
||||
switch(tinyDb.getInt("fileviewerSourceCodeThemeId")) {
|
||||
switch(tinyDB.getInt("fileviewerSourceCodeThemeId")) {
|
||||
|
||||
case 1:
|
||||
|
||||
singleCodeContents.setTheme(Theme.ARDUINO_LIGHT);
|
||||
break;
|
||||
case 2:
|
||||
|
||||
singleCodeContents.setTheme(Theme.GITHUB);
|
||||
break;
|
||||
case 3:
|
||||
|
||||
singleCodeContents.setTheme(Theme.FAR);
|
||||
break;
|
||||
case 4:
|
||||
|
||||
singleCodeContents.setTheme(Theme.IR_BLACK);
|
||||
break;
|
||||
case 5:
|
||||
|
||||
singleCodeContents.setTheme(Theme.ANDROID_STUDIO);
|
||||
break;
|
||||
default:
|
||||
|
||||
singleCodeContents.setTheme(Theme.MONOKAI_SUBLIME);
|
||||
}
|
||||
|
||||
singleCodeContents.setSource(appUtil.decodeBase64(response.body().getContent()));
|
||||
|
||||
}
|
||||
else if(appUtil.pdfExtension(fileExtension)) { // file is pdf
|
||||
|
||||
@ -248,7 +229,7 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
singleCodeContents.setVisibility(View.GONE);
|
||||
pdfViewFrame.setVisibility(View.VISIBLE);
|
||||
|
||||
pdfNightMode = tinyDb.getBoolean("enablePdfMode");
|
||||
pdfNightMode = tinyDB.getBoolean("enablePdfMode");
|
||||
|
||||
decodedPdf = Base64.decode(response.body().getContent(), Base64.DEFAULT);
|
||||
pdfView.fromBytes(decodedPdf).enableSwipe(true).swipeHorizontal(false).enableDoubletap(true).defaultPage(0).enableAnnotationRendering(false).password(null).scrollHandle(null).enableAntialiasing(true).spacing(0).autoSpacing(true).pageFitPolicy(FitPolicy.WIDTH).fitEachPage(true).pageSnap(false).pageFling(true).nightMode(pdfNightMode).load();
|
||||
@ -264,7 +245,6 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
singleFileContents.setText(getResources().getString(R.string.excludeFilesInFileviewer));
|
||||
singleFileContents.setGravity(Gravity.CENTER);
|
||||
singleFileContents.setTypeface(null, Typeface.BOLD);
|
||||
|
||||
}
|
||||
else { // file type not known - plain text view
|
||||
|
||||
@ -274,37 +254,30 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
||||
|
||||
singleFileContents.setText(appUtil.decodeBase64(response.body().getContent()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
singleFileContents.setText("");
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
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));
|
||||
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
|
||||
}
|
||||
else if(response.code() == 404) {
|
||||
|
||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -324,7 +297,9 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
inflater.inflate(R.menu.files_view_menu, menu);
|
||||
|
||||
String fileExtension = FileUtils.getExtension(singleFileName);
|
||||
|
||||
if(!fileExtension.equalsIgnoreCase("md")) {
|
||||
|
||||
menu.getItem(0).setVisible(false);
|
||||
}
|
||||
|
||||
@ -336,89 +311,42 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
|
||||
int id = item.getItemId();
|
||||
|
||||
switch(id) {
|
||||
case android.R.id.home:
|
||||
if(id == 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);
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
else if(id == R.id.genericMenu) {
|
||||
|
||||
BottomSheetFileViewerFragment bottomSheet = new BottomSheetFileViewerFragment();
|
||||
bottomSheet.show(getSupportFragmentManager(), "fileViewerBottomSheet");
|
||||
return true;
|
||||
}
|
||||
else if(id == R.id.markdown) {
|
||||
|
||||
new Markdown(ctx, appUtil.decodeBase64(tinyDB.getString("downloadFileContents")), singleFileContents);
|
||||
|
||||
if(!tinyDB.getBoolean("enableMarkdownInFileView")) {
|
||||
|
||||
singleCodeContents.setVisibility(View.GONE);
|
||||
singleFileContentsFrame.setVisibility(View.VISIBLE);
|
||||
singleFileContents.setVisibility(View.VISIBLE);
|
||||
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;
|
||||
}
|
||||
else {
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -432,15 +360,18 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
if("deleteFile".equals(text)) {
|
||||
|
||||
String fileExtension = FileUtils.getExtension(singleFileName);
|
||||
String data = appUtil.decodeBase64(tinyDb.getString("downloadFileContents"));
|
||||
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", "");
|
||||
}
|
||||
|
||||
@ -450,15 +381,18 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
if("editFile".equals(text)) {
|
||||
|
||||
String fileExtension = FileUtils.getExtension(singleFileName);
|
||||
String data = appUtil.decodeBase64(tinyDb.getString("downloadFileContents"));
|
||||
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", "");
|
||||
}
|
||||
|
||||
@ -469,11 +403,9 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
|
||||
private void requestFileDownload() {
|
||||
|
||||
if(!tinyDb.getString("downloadFileContents").isEmpty()) {
|
||||
if(!tinyDB.getString("downloadFileContents").isEmpty()) {
|
||||
|
||||
int CREATE_REQUEST_CODE = 40;
|
||||
|
||||
File outputFileName = new File(tinyDb.getString("downloadFileName"));
|
||||
File outputFileName = new File(tinyDB.getString("downloadFileName"));
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_CREATE_DOCUMENT);
|
||||
|
||||
@ -481,48 +413,48 @@ public class FileViewActivity extends BaseActivity implements BottomSheetFileVie
|
||||
intent.setType("*/*");
|
||||
intent.putExtra(Intent.EXTRA_TITLE, outputFileName.getName());
|
||||
|
||||
startActivityForResult(intent, CREATE_REQUEST_CODE);
|
||||
|
||||
fileDownloadActivityResultLauncher.launch(intent);
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.waitLoadingDownloadFile));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
|
||||
ActivityResultLauncher<Intent> fileDownloadActivityResultLauncher = registerForActivityResult(
|
||||
new ActivityResultContracts.StartActivityForResult(), new ActivityResultCallback<ActivityResult>() {
|
||||
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
@Override
|
||||
public void onActivityResult(ActivityResult result) {
|
||||
|
||||
if(requestCode == 40 && resultCode == RESULT_OK) {
|
||||
if (result.getResultCode() == Activity.RESULT_OK) {
|
||||
|
||||
try {
|
||||
Intent data = result.getData();
|
||||
|
||||
assert data != null;
|
||||
Uri uri = data.getData();
|
||||
try {
|
||||
|
||||
assert uri != null;
|
||||
OutputStream outputStream = getContentResolver().openOutputStream(uri);
|
||||
assert data != null;
|
||||
Uri uri = data.getData();
|
||||
|
||||
byte[] dataAsBytes = Base64.decode(tinyDb.getString("downloadFileContents"), 0);
|
||||
assert uri != null;
|
||||
OutputStream outputStream = getContentResolver().openOutputStream(uri);
|
||||
|
||||
assert outputStream != null;
|
||||
outputStream.write(dataAsBytes);
|
||||
outputStream.close();
|
||||
byte[] dataAsBytes = Base64.decode(tinyDB.getString("downloadFileContents"), 0);
|
||||
|
||||
Toasty.success(ctx, getString(R.string.downloadFileSaved));
|
||||
assert outputStream != null;
|
||||
outputStream.write(dataAsBytes);
|
||||
outputStream.close();
|
||||
|
||||
Toasty.success(ctx, getString(R.string.downloadFileSaved));
|
||||
|
||||
}
|
||||
catch(IOException e) {
|
||||
|
||||
Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
}
|
||||
catch(IOException e) {
|
||||
|
||||
Log.e("errorFileDownloading", Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
private void initCloseListener() {
|
||||
|
||||
|
@ -1,18 +1,15 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
@ -50,11 +47,11 @@ 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.Markdown;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.UserMentions;
|
||||
import org.mian.gitnex.helpers.Version;
|
||||
import org.mian.gitnex.models.Collaborators;
|
||||
import org.mian.gitnex.models.Issues;
|
||||
@ -62,30 +59,15 @@ import org.mian.gitnex.models.Labels;
|
||||
import org.mian.gitnex.models.UpdateIssueAssignees;
|
||||
import org.mian.gitnex.models.WatchInfo;
|
||||
import org.mian.gitnex.viewmodels.IssueCommentsViewModel;
|
||||
import org.mian.gitnex.views.ReactionList;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
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;
|
||||
import retrofit2.Response;
|
||||
@ -97,13 +79,7 @@ import retrofit2.Response;
|
||||
public class IssueDetailActivity extends BaseActivity implements LabelsListAdapter.LabelsListAdapterListener, AssigneesListAdapter.AssigneesListAdapterListener, BottomSheetSingleIssueFragment.BottomSheetListener {
|
||||
|
||||
private IssueCommentsAdapter adapter;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private TinyDB tinyDb;
|
||||
|
||||
private String instanceUrl;
|
||||
private String loginUid;
|
||||
private String instanceToken;
|
||||
private String repoOwner;
|
||||
private String repoName;
|
||||
private int issueIndex;
|
||||
@ -135,21 +111,16 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
tinyDb = new TinyDB(appCtx);
|
||||
|
||||
viewBinding = ActivityIssueDetailBinding.inflate(getLayoutInflater());
|
||||
View view = viewBinding.getRoot();
|
||||
setContentView(view);
|
||||
|
||||
instanceUrl = tinyDb.getString("instanceUrl");
|
||||
loginUid = tinyDb.getString("loginUid");
|
||||
instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
repoOwner = parts[0];
|
||||
repoName = parts[1];
|
||||
issueIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
||||
issueIndex = Integer.parseInt(tinyDB.getString("issueNumber"));
|
||||
|
||||
setSupportActionBar(viewBinding.toolbar);
|
||||
Objects.requireNonNull(getSupportActionBar()).setTitle(repoName);
|
||||
@ -162,12 +133,18 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(viewBinding.recyclerView.getContext(), DividerItemDecoration.VERTICAL);
|
||||
viewBinding.recyclerView.addItemDecoration(dividerItemDecoration);
|
||||
|
||||
viewBinding.addNewComment.setOnClickListener(v -> BottomSheetReplyFragment.newInstance(new Bundle()).show(getSupportFragmentManager(), "replyBottomSheet"));
|
||||
viewBinding.addNewComment.setOnClickListener(v -> {
|
||||
|
||||
BottomSheetReplyFragment bottomSheetReplyFragment = BottomSheetReplyFragment.newInstance(new Bundle());
|
||||
bottomSheetReplyFragment.setOnInteractedListener(this::onResume);
|
||||
bottomSheetReplyFragment.show(getSupportFragmentManager(), "replyBottomSheet");
|
||||
|
||||
});
|
||||
|
||||
labelsAdapter = new LabelsListAdapter(labelsList, IssueDetailActivity.this, currentLabelsIds);
|
||||
assigneesAdapter = new AssigneesListAdapter(ctx, assigneesList, IssueDetailActivity.this, currentAssignees);
|
||||
LabelsActions.getCurrentIssueLabels(ctx, instanceUrl, loginUid, instanceToken, repoOwner, repoName, issueIndex, currentLabelsIds);
|
||||
AssigneesActions.getCurrentIssueAssignees(ctx, instanceUrl, loginUid, instanceToken, repoOwner, repoName, issueIndex, currentAssignees);
|
||||
LabelsActions.getCurrentIssueLabels(ctx, repoOwner, repoName, issueIndex, currentLabelsIds);
|
||||
AssigneesActions.getCurrentIssueAssignees(ctx, repoOwner, repoName, issueIndex, currentAssignees);
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
|
||||
@ -196,14 +173,14 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
viewBinding.pullToRefresh.setRefreshing(false);
|
||||
IssueCommentsViewModel
|
||||
.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex,
|
||||
.loadIssueComments(Authorization.get(ctx), repoOwner, repoName, issueIndex,
|
||||
ctx);
|
||||
|
||||
}, 500));
|
||||
|
||||
Typeface myTypeface;
|
||||
|
||||
switch(tinyDb.getInt("customFontId", -1)) {
|
||||
switch(tinyDB.getInt("customFontId", -1)) {
|
||||
|
||||
case 1:
|
||||
myTypeface = Typeface.createFromAsset(Objects.requireNonNull(ctx).getAssets(), "fonts/manroperegular.ttf");
|
||||
@ -222,8 +199,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
viewBinding.toolbarTitle.setTypeface(myTypeface);
|
||||
viewBinding.toolbarTitle.setText(repoName);
|
||||
|
||||
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
||||
fetchDataAsync(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
||||
getSingleIssue(repoOwner, repoName, issueIndex);
|
||||
fetchDataAsync(repoOwner, repoName, issueIndex);
|
||||
|
||||
}
|
||||
|
||||
@ -232,6 +209,10 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
switch(text) {
|
||||
|
||||
case "onResume":
|
||||
onResume();
|
||||
break;
|
||||
|
||||
case "showLabels":
|
||||
showLabels();
|
||||
break;
|
||||
@ -292,7 +273,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
}
|
||||
});
|
||||
|
||||
AssigneesActions.getRepositoryAssignees(ctx, instanceUrl, instanceToken, repoOwner, repoName, assigneesList, dialogAssignees, assigneesAdapter, assigneesBinding);
|
||||
dialogAssignees.show();
|
||||
AssigneesActions.getRepositoryAssignees(ctx, repoOwner, repoName, assigneesList, dialogAssignees, assigneesAdapter, assigneesBinding);
|
||||
}
|
||||
|
||||
public void showLabels() {
|
||||
@ -328,7 +310,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
}
|
||||
});
|
||||
|
||||
LabelsActions.getRepositoryLabels(ctx, instanceUrl, instanceToken, repoOwner, repoName, labelsList, dialogLabels, labelsAdapter, labelsBinding);
|
||||
dialogLabels.show();
|
||||
LabelsActions.getRepositoryLabels(ctx, repoOwner, repoName, labelsList, dialogLabels, labelsAdapter, labelsBinding);
|
||||
}
|
||||
|
||||
private void updateIssueAssignees() {
|
||||
@ -338,9 +321,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
Call<JsonElement> call3;
|
||||
|
||||
call3 = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.patchIssueAssignees(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, updateAssigneeJson);
|
||||
.getApiInterface(ctx)
|
||||
.patchIssueAssignees(Authorization.get(ctx), repoOwner, repoName, issueIndex, updateAssigneeJson);
|
||||
|
||||
call3.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -355,9 +337,9 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
viewBinding.frameAssignees.removeAllViews();
|
||||
viewBinding.frameLabels.removeAllViews();
|
||||
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
||||
getSingleIssue(repoOwner, repoName, issueIndex);
|
||||
currentAssignees.clear();
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> AssigneesActions.getCurrentIssueAssignees(ctx, instanceUrl, loginUid, instanceToken, repoOwner, repoName, issueIndex, currentAssignees), 1000);
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> AssigneesActions.getCurrentIssueAssignees(ctx, repoOwner, repoName, issueIndex, currentAssignees), 1000);
|
||||
}
|
||||
else if(response2.code() == 401) {
|
||||
|
||||
@ -394,9 +376,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
Labels patchIssueLabels = new Labels(labelsIds);
|
||||
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.updateIssueLabels(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex, patchIssueLabels);
|
||||
.getApiInterface(ctx)
|
||||
.updateIssueLabels(Authorization.get(ctx), repoOwner, repoName, issueIndex, patchIssueLabels);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -410,9 +391,9 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
viewBinding.frameAssignees.removeAllViews();
|
||||
viewBinding.frameLabels.removeAllViews();
|
||||
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
||||
getSingleIssue(repoOwner, repoName, issueIndex);
|
||||
currentLabelsIds.clear();
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> LabelsActions.getCurrentIssueLabels(ctx, instanceUrl, loginUid, instanceToken, repoOwner, repoName, issueIndex, currentLabelsIds), 1000);
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> LabelsActions.getCurrentIssueLabels(ctx, repoOwner, repoName, issueIndex, currentLabelsIds), 1000);
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -457,18 +438,21 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
int id = item.getItemId();
|
||||
|
||||
switch(id) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.genericMenu:
|
||||
BottomSheetSingleIssueFragment bottomSheet = new BottomSheetSingleIssueFragment();
|
||||
bottomSheet.show(getSupportFragmentManager(), "singleIssueBottomSheet");
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
if(id == android.R.id.home) {
|
||||
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
else if(id == R.id.genericMenu) {
|
||||
|
||||
BottomSheetSingleIssueFragment bottomSheet = new BottomSheetSingleIssueFragment();
|
||||
bottomSheet.show(getSupportFragmentManager(), "singleIssueBottomSheet");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -476,84 +460,87 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
super.onResume();
|
||||
|
||||
if(tinyDb.getBoolean("commentPosted")) {
|
||||
if(tinyDB.getBoolean("commentPosted")) {
|
||||
|
||||
viewBinding.scrollViewComments.post(() -> {
|
||||
|
||||
IssueCommentsViewModel
|
||||
.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex,
|
||||
.loadIssueComments(Authorization.get(ctx), repoOwner, repoName, issueIndex,
|
||||
ctx);
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> viewBinding.scrollViewComments.fullScroll(ScrollView.FOCUS_DOWN), 1000);
|
||||
|
||||
tinyDb.putBoolean("commentPosted", false);
|
||||
|
||||
tinyDB.putBoolean("commentPosted", false);
|
||||
});
|
||||
}
|
||||
|
||||
if(tinyDb.getBoolean("commentEdited")) {
|
||||
if(tinyDB.getBoolean("commentEdited")) {
|
||||
|
||||
viewBinding.scrollViewComments.post(() -> {
|
||||
|
||||
IssueCommentsViewModel
|
||||
.loadIssueComments(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex,
|
||||
.loadIssueComments(Authorization.get(ctx), repoOwner, repoName, issueIndex,
|
||||
ctx);
|
||||
tinyDb.putBoolean("commentEdited", false);
|
||||
|
||||
tinyDB.putBoolean("commentEdited", false);
|
||||
});
|
||||
}
|
||||
|
||||
if(tinyDb.getBoolean("singleIssueUpdate")) {
|
||||
if(tinyDB.getBoolean("singleIssueUpdate")) {
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
viewBinding.frameAssignees.removeAllViews();
|
||||
viewBinding.frameLabels.removeAllViews();
|
||||
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
||||
tinyDb.putBoolean("singleIssueUpdate", false);
|
||||
getSingleIssue(repoOwner, repoName, issueIndex);
|
||||
tinyDB.putBoolean("singleIssueUpdate", false);
|
||||
|
||||
}, 500);
|
||||
|
||||
}
|
||||
|
||||
if(tinyDb.getBoolean("issueEdited")) {
|
||||
if(tinyDB.getBoolean("issueEdited")) {
|
||||
|
||||
new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
viewBinding.frameAssignees.removeAllViews();
|
||||
viewBinding.frameLabels.removeAllViews();
|
||||
getSingleIssue(instanceUrl, instanceToken, repoOwner, repoName, issueIndex, loginUid);
|
||||
tinyDb.putBoolean("issueEdited", false);
|
||||
getSingleIssue(repoOwner, repoName, issueIndex);
|
||||
tinyDB.putBoolean("issueEdited", false);
|
||||
|
||||
}, 500);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void fetchDataAsync(String instanceUrl, String instanceToken, String owner, String repo, int index, String loginUid) {
|
||||
private void fetchDataAsync(String owner, String repo, int index) {
|
||||
|
||||
IssueCommentsViewModel issueCommentsModel = new ViewModelProvider(this).get(IssueCommentsViewModel.class);
|
||||
|
||||
issueCommentsModel.getIssueCommentList(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), owner, repo, index, ctx)
|
||||
issueCommentsModel.getIssueCommentList(Authorization.get(ctx), owner, repo, index, ctx)
|
||||
.observe(this, issueCommentsMain -> {
|
||||
|
||||
assert issueCommentsMain != null;
|
||||
|
||||
if(issueCommentsMain.size() > 0) {
|
||||
|
||||
viewBinding.divider.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
adapter = new IssueCommentsAdapter(ctx, getSupportFragmentManager(), issueCommentsMain);
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("repoOwner", repoOwner);
|
||||
bundle.putString("repoName", repoName);
|
||||
bundle.putInt("issueNumber", issueIndex);
|
||||
|
||||
adapter = new IssueCommentsAdapter(ctx, bundle, issueCommentsMain, getSupportFragmentManager(), this::onResume);
|
||||
|
||||
viewBinding.recyclerView.setAdapter(adapter);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void getSingleIssue(String instanceUrl, String instanceToken, String repoOwner, String repoName, int issueIndex, String loginUid) {
|
||||
private void getSingleIssue(String repoOwner, String repoName, int issueIndex) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
Call<Issues> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
||||
.getIssueByIndex(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, issueIndex);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
Call<Issues> call = RetrofitClient.getApiInterface(ctx)
|
||||
.getIssueByIndex(Authorization.get(ctx), repoOwner, repoName, issueIndex);
|
||||
|
||||
call.enqueue(new Callback<Issues>() {
|
||||
|
||||
@ -566,6 +553,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
assert singleIssue != null;
|
||||
|
||||
viewBinding.issuePrState.setVisibility(View.VISIBLE);
|
||||
|
||||
if(singleIssue.getPull_request() != null) {
|
||||
|
||||
if(singleIssue.getPull_request().isMerged()) { // merged
|
||||
@ -586,49 +574,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
viewBinding.issuePrState.setImageResource(R.drawable.ic_issue_closed_red);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
tinyDb.putString("issueState", singleIssue.getState());
|
||||
@ -641,8 +587,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
.getString(R.string.hash) + singleIssue.getNumber() + "</font>";
|
||||
viewBinding.issueTitle.setText(Html.fromHtml(issueNumber_ + " " + singleIssue.getTitle()));
|
||||
String cleanIssueDescription = singleIssue.getBody().trim();
|
||||
Spanned bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(cleanIssueDescription));
|
||||
markwon.setParsedMarkdown(viewBinding.issueDescription, UserMentions.UserMentionsFunc(ctx, bodyWithMD, cleanIssueDescription));
|
||||
|
||||
new Markdown(ctx, EmojiParser.parseToUnicode(cleanIssueDescription), viewBinding.issueDescription);
|
||||
|
||||
RelativeLayout.LayoutParams paramsDesc = (RelativeLayout.LayoutParams) viewBinding.issueDescription.getLayoutParams();
|
||||
|
||||
@ -650,7 +596,9 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
params1.setMargins(15, 0, 0, 0);
|
||||
|
||||
if(singleIssue.getAssignees() != null) {
|
||||
|
||||
viewBinding.assigneesScrollView.setVisibility(View.VISIBLE);
|
||||
|
||||
for(int i = 0; i < singleIssue.getAssignees().size(); i++) {
|
||||
|
||||
ImageView assigneesView = new ImageView(ctx);
|
||||
@ -662,17 +610,19 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
viewBinding.frameAssignees.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));
|
||||
}
|
||||
else {
|
||||
|
||||
assigneesView.setOnClickListener(
|
||||
new ClickListener(getString(R.string.assignedTo, singleIssue.getAssignees().get(i).getLogin()), ctx));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
viewBinding.assigneesScrollView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@ -681,6 +631,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
params.setMargins(0, 0, 15, 0);
|
||||
|
||||
if(singleIssue.getLabels() != null) {
|
||||
|
||||
viewBinding.labelsScrollView.setVisibility(View.VISIBLE);
|
||||
|
||||
for(int i = 0; i < singleIssue.getLabels().size(); i++) {
|
||||
@ -704,16 +655,17 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
labelsView.setImageDrawable(drawable);
|
||||
viewBinding.frameLabels.addView(labelsView);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
viewBinding.labelsScrollView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(singleIssue.getDue_date() != null) {
|
||||
|
||||
if(timeFormat.equals("normal") || timeFormat.equals("pretty")) {
|
||||
|
||||
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", new Locale(locale));
|
||||
String dueDate = formatter.format(singleIssue.getDue_date());
|
||||
viewBinding.issueDueDate.setText(dueDate);
|
||||
@ -721,11 +673,11 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getDue_date()), ctx));
|
||||
}
|
||||
else if(timeFormat.equals("normal1")) {
|
||||
|
||||
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy", new Locale(locale));
|
||||
String dueDate = formatter.format(singleIssue.getDue_date());
|
||||
viewBinding.issueDueDate.setText(dueDate);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
@ -735,6 +687,7 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
String edited;
|
||||
|
||||
if(!singleIssue.getUpdated_at().equals(singleIssue.getCreated_at())) {
|
||||
|
||||
edited = getString(R.string.colorfulBulletSpan) + getString(R.string.modifiedText);
|
||||
viewBinding.issueModified.setVisibility(View.VISIBLE);
|
||||
viewBinding.issueModified.setText(edited);
|
||||
@ -742,22 +695,27 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getUpdated_at()), ctx));
|
||||
}
|
||||
else {
|
||||
|
||||
viewBinding.issueModified.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
|
||||
if((singleIssue.getDue_date() == null && singleIssue.getMilestone() == null) && singleIssue.getAssignees() != null) {
|
||||
|
||||
paramsDesc.setMargins(0, 35, 0, 0);
|
||||
viewBinding.issueDescription.setLayoutParams(paramsDesc);
|
||||
}
|
||||
else if(singleIssue.getDue_date() == null && singleIssue.getMilestone() == null) {
|
||||
|
||||
paramsDesc.setMargins(0, 55, 0, 0);
|
||||
viewBinding.issueDescription.setLayoutParams(paramsDesc);
|
||||
}
|
||||
else if(singleIssue.getAssignees() == null) {
|
||||
|
||||
paramsDesc.setMargins(0, 35, 0, 0);
|
||||
viewBinding.issueDescription.setLayoutParams(paramsDesc);
|
||||
}
|
||||
else {
|
||||
|
||||
paramsDesc.setMargins(0, 15, 0, 0);
|
||||
viewBinding.issueDescription.setLayoutParams(paramsDesc);
|
||||
}
|
||||
@ -766,30 +724,51 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
viewBinding.issueCreatedTime.setVisibility(View.VISIBLE);
|
||||
|
||||
if(timeFormat.equals("pretty")) {
|
||||
|
||||
viewBinding.issueCreatedTime
|
||||
.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(singleIssue.getCreated_at()), ctx));
|
||||
}
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("repoOwner", repoOwner);
|
||||
bundle.putString("repoName", repoName);
|
||||
bundle.putInt("issueId", singleIssue.getNumber());
|
||||
|
||||
ReactionList reactionList = new ReactionList(ctx, bundle);
|
||||
|
||||
viewBinding.commentReactionBadges.removeAllViews();
|
||||
viewBinding.commentReactionBadges.addView(reactionList);
|
||||
|
||||
reactionList.setOnReactionAddedListener(() -> {
|
||||
|
||||
if(viewBinding.commentReactionBadges.getVisibility() != View.VISIBLE) {
|
||||
viewBinding.commentReactionBadges.post(() -> viewBinding.commentReactionBadges.setVisibility(View.VISIBLE));
|
||||
}
|
||||
});
|
||||
|
||||
if(singleIssue.getMilestone() != null) {
|
||||
|
||||
viewBinding.issueMilestone.setVisibility(View.VISIBLE);
|
||||
viewBinding.issueMilestone.setText(getString(R.string.issueMilestone, singleIssue.getMilestone().getTitle()));
|
||||
}
|
||||
else {
|
||||
|
||||
viewBinding.issueMilestone.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(!singleIssue.getUser().getFull_name().equals("")) {
|
||||
|
||||
viewBinding.assigneeAvatar.setOnClickListener(
|
||||
new ClickListener(ctx.getResources().getString(R.string.issueCreator) + singleIssue.getUser().getFull_name(), ctx));
|
||||
}
|
||||
else {
|
||||
|
||||
viewBinding.assigneeAvatar.setOnClickListener(
|
||||
new ClickListener(ctx.getResources().getString(R.string.issueCreator) + singleIssue.getUser().getLogin(), ctx));
|
||||
}
|
||||
|
||||
viewBinding.progressBar.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
|
||||
else if(response.code() == 401) {
|
||||
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||
@ -798,7 +777,21 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else if(response.code() == 404) {
|
||||
|
||||
if(tinyDb.getString("issueType").equals("Issue")) {
|
||||
|
||||
Toasty.warning(ctx, getResources().getString(R.string.noDataIssueTab));
|
||||
}
|
||||
else if(tinyDb.getString("issueType").equals("Pull")) {
|
||||
|
||||
Toasty.warning(ctx, getResources().getString(R.string.noDataPullRequests));
|
||||
}
|
||||
|
||||
Intent mainIntent = new Intent(ctx, MainActivity.class);
|
||||
ctx.startActivity(mainIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -811,8 +804,8 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
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.getApiInterface(appCtx)
|
||||
.checkIssueWatchStatus(Authorization.get(ctx), repoOwner, repoName, issueIndex);
|
||||
|
||||
call2.enqueue(new Callback<WatchInfo>() {
|
||||
|
||||
@ -823,21 +816,17 @@ public class IssueDetailActivity extends BaseActivity implements LabelsListAdapt
|
||||
|
||||
assert response.body() != null;
|
||||
tinyDb.putBoolean("issueSubscribed", response.body().getSubscribed());
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
tinyDb.putBoolean("issueSubscribed", false);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<WatchInfo> call, @NonNull Throwable t) {
|
||||
|
||||
tinyDb.putBoolean("issueSubscribed", false);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -1,16 +1,15 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioGroup;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
@ -19,7 +18,7 @@ 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.NetworkStatusObserver;
|
||||
import org.mian.gitnex.helpers.PathsHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
@ -47,16 +46,12 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
private enum LoginType {BASIC, TOKEN}
|
||||
|
||||
private Context appCtx;
|
||||
private Context ctx = this;
|
||||
private TinyDB tinyDB;
|
||||
|
||||
private Button loginButton;
|
||||
private EditText instanceUrlET, loginUidET, loginPassword, otpCode, loginTokenCode;
|
||||
private Spinner protocolSpinner;
|
||||
private TextView otpInfo;
|
||||
private AutoCompleteTextView protocolSpinner;
|
||||
private RadioGroup loginMethod;
|
||||
private String device_id = "token";
|
||||
private String selectedProtocol;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId() {
|
||||
@ -68,70 +63,77 @@ public class LoginActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
tinyDB = new TinyDB(appCtx);
|
||||
NetworkObserver networkMonitor = new NetworkObserver(ctx);
|
||||
NetworkStatusObserver networkStatusObserver = NetworkStatusObserver.get(ctx);
|
||||
|
||||
loginButton = findViewById(R.id.login_button);
|
||||
instanceUrlET = findViewById(R.id.instance_url);
|
||||
loginUidET = findViewById(R.id.login_uid);
|
||||
loginPassword = findViewById(R.id.login_passwd);
|
||||
otpCode = findViewById(R.id.otpCode);
|
||||
otpInfo = findViewById(R.id.otpInfo);
|
||||
protocolSpinner = findViewById(R.id.httpsSpinner);
|
||||
loginMethod = findViewById(R.id.loginMethod);
|
||||
loginTokenCode = findViewById(R.id.loginTokenCode);
|
||||
|
||||
((TextView) findViewById(R.id.appVersion)).setText(AppUtil.getAppVersion(appCtx));
|
||||
|
||||
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(LoginActivity.this, R.layout.spinner_item, Protocol.values());
|
||||
adapterProtocols.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
||||
ArrayAdapter<Protocol> adapterProtocols = new ArrayAdapter<>(LoginActivity.this, R.layout.list_spinner_items, Protocol.values());
|
||||
|
||||
protocolSpinner.setAdapter(adapterProtocols);
|
||||
protocolSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
protocolSpinner.setSelection(0);
|
||||
protocolSpinner.setOnItemClickListener((parent, view, position, id) -> {
|
||||
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
|
||||
selectedProtocol = String.valueOf(parent.getItemAtPosition(position));
|
||||
|
||||
if(protocolSpinner.getSelectedItem() == Protocol.HTTP) {
|
||||
Toasty.warning(ctx, getResources().getString(R.string.protocolError));
|
||||
}
|
||||
if(selectedProtocol.equals(String.valueOf(Protocol.HTTP))) {
|
||||
|
||||
Toasty.warning(ctx, getResources().getString(R.string.protocolError));
|
||||
}
|
||||
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if(R.id.loginToken == loginMethod.getCheckedRadioButtonId()) {
|
||||
|
||||
AppUtil.setMultiVisibility(View.GONE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
||||
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
|
||||
AppUtil.setMultiVisibility(View.VISIBLE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
||||
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
loginMethod.setOnCheckedChangeListener((group, checkedId) -> {
|
||||
|
||||
if(checkedId == R.id.loginToken) {
|
||||
|
||||
AppUtil.setMultiVisibility(View.GONE, loginUidET, loginPassword, otpCode, otpInfo);
|
||||
loginTokenCode.setVisibility(View.VISIBLE);
|
||||
|
||||
AppUtil.setMultiVisibility(View.GONE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
||||
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
|
||||
AppUtil.setMultiVisibility(View.VISIBLE, loginUidET, loginPassword, otpCode, otpInfo);
|
||||
loginTokenCode.setVisibility(View.GONE);
|
||||
|
||||
AppUtil.setMultiVisibility(View.VISIBLE, findViewById(R.id.login_uidLayout), findViewById(R.id.login_passwdLayout), findViewById(R.id.otpCodeLayout));
|
||||
findViewById(R.id.loginTokenCodeLayout).setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
networkMonitor.onInternetStateListener(isAvailable -> {
|
||||
Handler handler = new Handler(getMainLooper());
|
||||
|
||||
if(isAvailable) {
|
||||
networkStatusObserver.registerNetworkStatusListener(hasNetworkConnection -> {
|
||||
|
||||
enableProcessButton();
|
||||
}
|
||||
else {
|
||||
handler.post(() -> {
|
||||
|
||||
disableProcessButton();
|
||||
loginButton.setText(getResources().getString(R.string.btnLogin));
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
}
|
||||
if(hasNetworkConnection) {
|
||||
|
||||
enableProcessButton();
|
||||
}
|
||||
else {
|
||||
|
||||
disableProcessButton();
|
||||
loginButton.setText(getResources().getString(R.string.btnLogin));
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
loadDefaults();
|
||||
@ -140,25 +142,29 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
disableProcessButton();
|
||||
login();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void login() {
|
||||
|
||||
try {
|
||||
|
||||
if(selectedProtocol == null) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.protocolEmptyError));
|
||||
enableProcessButton();
|
||||
return;
|
||||
}
|
||||
|
||||
String loginUid = loginUidET.getText().toString();
|
||||
String loginPass = loginPassword.getText().toString();
|
||||
String loginToken = loginTokenCode.getText().toString().trim();
|
||||
|
||||
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 instanceUrl = UrlBuilder.fromUri(rawInstanceUrl).withScheme(protocol.name().toLowerCase()).withPath(PathsHelper.join(rawInstanceUrl.getPath(), "/api/v1/"))
|
||||
URI instanceUrl = UrlBuilder.fromUri(rawInstanceUrl).withScheme(selectedProtocol.toLowerCase()).withPath(PathsHelper.join(rawInstanceUrl.getPath(), "/api/v1/"))
|
||||
.toUri();
|
||||
|
||||
tinyDB.putString("loginType", loginType.name().toLowerCase());
|
||||
@ -170,7 +176,6 @@ public class LoginActivity extends BaseActivity {
|
||||
Toasty.error(ctx, getResources().getString(R.string.emptyFieldURL));
|
||||
enableProcessButton();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(loginType == LoginType.BASIC) {
|
||||
@ -180,14 +185,12 @@ public class LoginActivity extends BaseActivity {
|
||||
Toasty.warning(ctx, getResources().getString(R.string.loginOTPTypeError));
|
||||
enableProcessButton();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(rawInstanceUrl.getUserInfo() != null) {
|
||||
|
||||
tinyDB.putString("basicAuthPassword", loginPass);
|
||||
tinyDB.putBoolean("basicAuthFlag", true);
|
||||
|
||||
}
|
||||
|
||||
if(loginUid.equals("")) {
|
||||
@ -195,7 +198,6 @@ public class LoginActivity extends BaseActivity {
|
||||
Toasty.error(ctx, getResources().getString(R.string.emptyFieldUsername));
|
||||
enableProcessButton();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(loginPass.equals("")) {
|
||||
@ -203,13 +205,12 @@ public class LoginActivity extends BaseActivity {
|
||||
Toasty.error(ctx, getResources().getString(R.string.emptyFieldPassword));
|
||||
enableProcessButton();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
int loginOTP = (otpCode.length() > 0) ? Integer.parseInt(otpCode.getText().toString().trim()) : 0;
|
||||
tinyDB.putString("loginUid", loginUid);
|
||||
|
||||
versionCheck(instanceUrl.toString(), loginUid, loginPass, loginOTP, loginToken, loginType);
|
||||
versionCheck(loginUid, loginPass, loginOTP, loginToken, loginType);
|
||||
|
||||
}
|
||||
else {
|
||||
@ -219,11 +220,9 @@ public class LoginActivity extends BaseActivity {
|
||||
Toasty.error(ctx, getResources().getString(R.string.loginTokenError));
|
||||
enableProcessButton();
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
versionCheck(instanceUrl.toString(), loginUid, loginPass, 123, loginToken, loginType);
|
||||
|
||||
versionCheck(loginUid, loginPass, 123, loginToken, loginType);
|
||||
}
|
||||
|
||||
}
|
||||
@ -232,27 +231,25 @@ public class LoginActivity extends BaseActivity {
|
||||
Log.e("onFailure-login", e.toString());
|
||||
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,
|
||||
private void versionCheck(final String loginUid, final String loginPass, final int loginOTP, final String loginToken,
|
||||
final LoginType loginType) {
|
||||
|
||||
Call<GiteaVersion> callVersion;
|
||||
|
||||
if(!loginToken.equals("")) {
|
||||
|
||||
callVersion = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithToken("token " + loginToken);
|
||||
callVersion = RetrofitClient.getApiInterface(appCtx).getGiteaVersionWithToken("token " + loginToken);
|
||||
}
|
||||
else {
|
||||
|
||||
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);
|
||||
|
||||
(loginOTP != 0) ? RetrofitClient.getApiInterface(appCtx).getGiteaVersionWithOTP(credential, loginOTP) :
|
||||
RetrofitClient.getApiInterface(appCtx).getGiteaVersionWithBasic(credential);
|
||||
}
|
||||
|
||||
callVersion.enqueue(new Callback<GiteaVersion>() {
|
||||
@ -263,9 +260,10 @@ public class LoginActivity extends BaseActivity {
|
||||
if(responseVersion.code() == 200) {
|
||||
|
||||
GiteaVersion version = responseVersion.body();
|
||||
|
||||
assert version != null;
|
||||
|
||||
if(!Version.valid(version.getVersion())) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.versionUnknown));
|
||||
enableProcessButton();
|
||||
return;
|
||||
@ -276,8 +274,10 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
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) -> {
|
||||
@ -289,7 +289,7 @@ public class LoginActivity extends BaseActivity {
|
||||
alertDialogBuilder.setPositiveButton(getString(R.string.textContinue), (dialog, which) -> {
|
||||
|
||||
dialog.dismiss();
|
||||
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
||||
login(loginType, loginUid, loginPass, loginOTP, loginToken);
|
||||
});
|
||||
|
||||
alertDialogBuilder.create().show();
|
||||
@ -297,32 +297,34 @@ public class LoginActivity extends BaseActivity {
|
||||
}
|
||||
else if(gitea_version.lessOrEqual(getString(R.string.versionHigh))) {
|
||||
|
||||
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
||||
login(loginType, loginUid, loginPass, loginOTP, loginToken);
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.warning(ctx, getResources().getString(R.string.versionUnsupportedNew));
|
||||
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
||||
login(loginType, loginUid, loginPass, loginOTP, loginToken);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else if(responseVersion.code() == 403) {
|
||||
|
||||
login(loginType, instanceUrl, loginUid, loginPass, loginOTP, loginToken);
|
||||
login(loginType, loginUid, loginPass, loginOTP, loginToken);
|
||||
}
|
||||
}
|
||||
|
||||
private void login(LoginType loginType, String instanceUrl, String loginUid, String loginPass, int loginOTP, String loginToken) {
|
||||
private void login(LoginType loginType, String loginUid, String loginPass, int loginOTP, String loginToken) {
|
||||
|
||||
// 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);
|
||||
|
||||
setup(loginUid, loginPass, loginOTP);
|
||||
}
|
||||
else if(loginType == LoginType.TOKEN) { // Token
|
||||
setupUsingExistingToken(instanceUrl, loginToken);
|
||||
|
||||
setupUsingExistingToken(loginToken);
|
||||
}
|
||||
}
|
||||
|
||||
@ -336,9 +338,9 @@ public class LoginActivity extends BaseActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private void setupUsingExistingToken(String instanceUrl, final String loginToken) {
|
||||
private void setupUsingExistingToken(final String loginToken) {
|
||||
|
||||
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserInfo("token " + loginToken);
|
||||
Call<UserInfo> call = RetrofitClient.getApiInterface(appCtx).getUserInfo("token " + loginToken);
|
||||
|
||||
call.enqueue(new Callback<UserInfo>() {
|
||||
|
||||
@ -350,6 +352,7 @@ public class LoginActivity extends BaseActivity {
|
||||
switch(response.code()) {
|
||||
|
||||
case 200:
|
||||
|
||||
assert userDetails != null;
|
||||
tinyDB.putBoolean("loggedInMode", true);
|
||||
tinyDB.putString(userDetails.getLogin() + "-token", loginToken);
|
||||
@ -357,14 +360,14 @@ public class LoginActivity extends BaseActivity {
|
||||
tinyDB.putString("userLogin", userDetails.getUsername());
|
||||
|
||||
// insert new account to db if does not exist
|
||||
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
||||
String accountName = userDetails.getUsername() + "@" + TinyDB.getInstance(ctx).getString("instanceUrl");
|
||||
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
||||
int checkAccount = userAccountsApi.getCount(accountName);
|
||||
long accountId;
|
||||
|
||||
if(checkAccount == 0) {
|
||||
|
||||
accountId = userAccountsApi.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), loginToken, "");
|
||||
accountId = userAccountsApi.insertNewAccount(accountName, TinyDB.getInstance(ctx).getString("instanceUrl"), userDetails.getUsername(), loginToken, "");
|
||||
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
||||
}
|
||||
else {
|
||||
@ -378,18 +381,16 @@ public class LoginActivity extends BaseActivity {
|
||||
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
||||
finish();
|
||||
break;
|
||||
|
||||
case 401:
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
||||
enableProcessButton();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -398,13 +399,12 @@ public class LoginActivity extends BaseActivity {
|
||||
Log.e("onFailure", t.toString());
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void setup(final String instanceUrl, final String loginUid, final String loginPass, final int loginOTP) {
|
||||
private void setup(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;
|
||||
@ -412,11 +412,11 @@ public class LoginActivity extends BaseActivity {
|
||||
Call<List<UserTokens>> call;
|
||||
if(loginOTP != 0) {
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserTokensWithOTP(credential, loginOTP, loginUid);
|
||||
call = RetrofitClient.getApiInterface(appCtx).getUserTokensWithOTP(credential, loginOTP, loginUid);
|
||||
}
|
||||
else {
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserTokens(credential, loginUid);
|
||||
call = RetrofitClient.getApiInterface(appCtx).getUserTokens(credential, loginUid);
|
||||
}
|
||||
|
||||
call.enqueue(new Callback<List<UserTokens>>() {
|
||||
@ -429,7 +429,9 @@ public class LoginActivity extends BaseActivity {
|
||||
if(response.code() == 200) {
|
||||
|
||||
assert userTokens != null;
|
||||
|
||||
for(UserTokens t : userTokens) {
|
||||
|
||||
if(t.getName().equals(tokenName)) {
|
||||
|
||||
// this app had created an token on this instance before
|
||||
@ -438,13 +440,14 @@ public class LoginActivity extends BaseActivity {
|
||||
Call<Void> delcall;
|
||||
if(loginOTP != 0) {
|
||||
|
||||
delcall = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
||||
delcall = RetrofitClient.getApiInterface(ctx)
|
||||
.deleteTokenWithOTP(credential, loginOTP, loginUid, t.getId());
|
||||
}
|
||||
else {
|
||||
|
||||
delcall = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().deleteToken(credential, loginUid, t.getId());
|
||||
delcall = RetrofitClient.getApiInterface(ctx).deleteToken(credential, loginUid, t.getId());
|
||||
}
|
||||
|
||||
delcall.enqueue(new Callback<Void>() {
|
||||
|
||||
@Override
|
||||
@ -452,13 +455,12 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
if(response.code() == 204) {
|
||||
|
||||
setupToken(instanceUrl, loginUid, loginPass, loginOTP, tokenName);
|
||||
setupToken(loginUid, loginPass, loginOTP, tokenName);
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -468,20 +470,18 @@ public class LoginActivity extends BaseActivity {
|
||||
Log.e("onFailure-login", t.toString());
|
||||
Toasty.error(ctx, getResources().getString(R.string.malformedJson));
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
setupToken(instanceUrl, loginUid, loginPass, loginOTP, tokenName);
|
||||
setupToken(loginUid, loginPass, loginOTP, tokenName);
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -491,13 +491,12 @@ public class LoginActivity extends BaseActivity {
|
||||
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) {
|
||||
private void setupToken(final String loginUid, final String loginPass, final int loginOTP, final String tokenName) {
|
||||
|
||||
final String credential = Credentials.basic(loginUid, loginPass, StandardCharsets.UTF_8);
|
||||
|
||||
@ -506,12 +505,13 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
if(loginOTP != 0) {
|
||||
|
||||
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
||||
callCreateToken = RetrofitClient.getApiInterface(ctx)
|
||||
.createNewTokenWithOTP(credential, loginOTP, loginUid, createUserToken);
|
||||
}
|
||||
else {
|
||||
|
||||
callCreateToken = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().createNewToken(credential, loginUid, createUserToken);
|
||||
callCreateToken = RetrofitClient.getApiInterface(ctx)
|
||||
.createNewToken(credential, loginUid, createUserToken);
|
||||
}
|
||||
|
||||
callCreateToken.enqueue(new Callback<UserTokens>() {
|
||||
@ -526,7 +526,7 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
if(!newToken.getSha1().equals("")) {
|
||||
|
||||
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface()
|
||||
Call<UserInfo> call = RetrofitClient.getApiInterface(ctx)
|
||||
.getUserInfo("token " + newToken.getSha1());
|
||||
|
||||
call.enqueue(new Callback<UserInfo>() {
|
||||
@ -539,6 +539,7 @@ public class LoginActivity extends BaseActivity {
|
||||
switch(response.code()) {
|
||||
|
||||
case 200:
|
||||
|
||||
assert userDetails != null;
|
||||
tinyDB.remove("loginPass");
|
||||
tinyDB.putBoolean("loggedInMode", true);
|
||||
@ -547,7 +548,7 @@ public class LoginActivity extends BaseActivity {
|
||||
tinyDB.putString(loginUid + "-token-last-eight", newToken.getToken_last_eight());
|
||||
|
||||
// insert new account to db if does not exist
|
||||
String accountName = userDetails.getUsername() + "@" + instanceUrl;
|
||||
String accountName = userDetails.getUsername() + "@" + TinyDB.getInstance(ctx).getString("instanceUrl");
|
||||
UserAccountsApi userAccountsApi = new UserAccountsApi(ctx);
|
||||
int checkAccount = userAccountsApi.getCount(accountName);
|
||||
long accountId;
|
||||
@ -555,7 +556,7 @@ public class LoginActivity extends BaseActivity {
|
||||
if(checkAccount == 0) {
|
||||
|
||||
accountId = userAccountsApi
|
||||
.insertNewAccount(accountName, instanceUrl, userDetails.getUsername(), newToken.getSha1(), "");
|
||||
.insertNewAccount(accountName, TinyDB.getInstance(ctx).getString("instanceUrl"), userDetails.getUsername(), newToken.getSha1(), "");
|
||||
tinyDB.putInt("currentActiveAccountId", (int) accountId);
|
||||
}
|
||||
else {
|
||||
@ -568,18 +569,16 @@ public class LoginActivity extends BaseActivity {
|
||||
startActivity(new Intent(LoginActivity.this, MainActivity.class));
|
||||
finish();
|
||||
break;
|
||||
|
||||
case 401:
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.unauthorizedApiError));
|
||||
enableProcessButton();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + response.code());
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -588,7 +587,6 @@ public class LoginActivity extends BaseActivity {
|
||||
Log.e("onFailure", t.toString());
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -597,7 +595,6 @@ public class LoginActivity extends BaseActivity {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericApiStatusError) + responseCreate.code());
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -613,17 +610,21 @@ public class LoginActivity extends BaseActivity {
|
||||
private void loadDefaults() {
|
||||
|
||||
if(tinyDB.getString("loginType").equals(LoginType.BASIC.name().toLowerCase())) {
|
||||
|
||||
loginMethod.check(R.id.loginUsernamePassword);
|
||||
}
|
||||
else {
|
||||
|
||||
loginMethod.check(R.id.loginToken);
|
||||
}
|
||||
|
||||
if(!tinyDB.getString("instanceUrlRaw").equals("")) {
|
||||
|
||||
instanceUrlET.setText(tinyDB.getString("instanceUrlRaw"));
|
||||
}
|
||||
|
||||
if(!tinyDB.getString("loginUid").equals("")) {
|
||||
|
||||
loginUidET.setText(tinyDB.getString("loginUid"));
|
||||
}
|
||||
|
||||
@ -634,9 +635,11 @@ public class LoginActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
if(!tinyDB.getString("uniqueAppId").isEmpty()) {
|
||||
|
||||
device_id = tinyDB.getString("uniqueAppId");
|
||||
}
|
||||
else {
|
||||
|
||||
device_id = UUID.randomUUID().toString();
|
||||
tinyDB.putString("uniqueAppId", device_id);
|
||||
}
|
||||
|
@ -77,11 +77,8 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
private ImageView userAvatarBackground;
|
||||
private ViewGroup navHeaderFrame;
|
||||
private TextView toolbarTitle;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private Typeface myTypeface;
|
||||
|
||||
private String instanceUrl;
|
||||
private String loginUid;
|
||||
private String instanceToken;
|
||||
|
||||
@ -99,63 +96,69 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
tinyDb.putBoolean("noConnection", false);
|
||||
tinyDB.putBoolean("noConnection", false);
|
||||
|
||||
String currentVersion = tinyDB.getString("giteaVersion");
|
||||
|
||||
Intent mainIntent = getIntent();
|
||||
String launchFragment = mainIntent.getStringExtra("launchFragment");
|
||||
|
||||
instanceUrl = tinyDb.getString("instanceUrl");
|
||||
loginUid = tinyDb.getString("loginUid");
|
||||
instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
loginUid = tinyDB.getString("loginUid");
|
||||
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||
|
||||
if(tinyDb.getString("dateFormat").isEmpty()) {
|
||||
tinyDb.putString("dateFormat", "pretty");
|
||||
if(tinyDB.getString("dateFormat").isEmpty()) {
|
||||
|
||||
tinyDB.putString("dateFormat", "pretty");
|
||||
}
|
||||
|
||||
if(tinyDb.getString("codeBlockStr").isEmpty()) {
|
||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorLightGreen));
|
||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
|
||||
if(tinyDB.getString("codeBlockStr").isEmpty()) {
|
||||
|
||||
tinyDB.putInt("codeBlockColor", getResources().getColor(R.color.colorLightGreen));
|
||||
tinyDB.putInt("codeBlockBackground", getResources().getColor(R.color.black));
|
||||
}
|
||||
|
||||
if(tinyDb.getString("enableCounterIssueBadgeInit").isEmpty()) {
|
||||
tinyDb.putBoolean("enableCounterIssueBadge", true);
|
||||
if(tinyDB.getString("enableCounterIssueBadgeInit").isEmpty()) {
|
||||
|
||||
tinyDB.putBoolean("enableCounterIssueBadge", true);
|
||||
}
|
||||
|
||||
if(tinyDb.getString("homeScreenStr").isEmpty()) {
|
||||
tinyDb.putInt("homeScreenId", 0);
|
||||
if(tinyDB.getString("homeScreenStr").isEmpty()) {
|
||||
|
||||
tinyDB.putString("homeScreenStr", "yes");
|
||||
tinyDB.putInt("homeScreenId", 0);
|
||||
}
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
|
||||
if(!tinyDb.getBoolean("loggedInMode")) {
|
||||
if(!tinyDB.getBoolean("loggedInMode")) {
|
||||
|
||||
logout(this, ctx);
|
||||
return;
|
||||
}
|
||||
|
||||
if(tinyDb.getInt("currentActiveAccountId") <= 0) {
|
||||
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);
|
||||
|
||||
switch(tinyDb.getInt("customFontId", -1)) {
|
||||
switch(tinyDB.getInt("customFontId", -1)) {
|
||||
|
||||
case 0:
|
||||
|
||||
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/roboto.ttf");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/sourcecodeproregular.ttf");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
myTypeface = Typeface.createFromAsset(getAssets(), "fonts/manroperegular.ttf");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
toolbarTitle.setTypeface(myTypeface);
|
||||
@ -165,37 +168,47 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
Fragment fragmentById = fm.findFragmentById(R.id.fragment_container);
|
||||
|
||||
if(fragmentById instanceof SettingsFragment) {
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleSettings));
|
||||
}
|
||||
else if(fragmentById instanceof MyRepositoriesFragment) {
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||
}
|
||||
else if(fragmentById instanceof StarredRepositoriesFragment) {
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||
}
|
||||
else if(fragmentById instanceof OrganizationsFragment) {
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||
}
|
||||
else if(fragmentById instanceof ExploreFragment) {
|
||||
|
||||
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 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));
|
||||
}
|
||||
|
||||
getNotificationsCount(instanceUrl, instanceToken);
|
||||
getNotificationsCount(instanceToken);
|
||||
|
||||
drawer = findViewById(R.id.drawer_layout);
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
@ -213,20 +226,15 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
@Override
|
||||
public void onDrawerOpened(@NonNull View drawerView) {
|
||||
|
||||
getNotificationsCount(instanceUrl, instanceToken);
|
||||
}
|
||||
if(tinyDB.getBoolean("noConnection")) {
|
||||
|
||||
@Override
|
||||
public void onDrawerSlide(@NonNull View drawerView, float slideOffset) {
|
||||
|
||||
if(tinyDb.getBoolean("noConnection")) {
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
tinyDb.putBoolean("noConnection", false);
|
||||
tinyDB.putBoolean("noConnection", false);
|
||||
}
|
||||
|
||||
String userEmailNav = tinyDb.getString("userEmail");
|
||||
String userFullNameNav = tinyDb.getString("userFullname");
|
||||
String userAvatarNav = tinyDb.getString("userAvatar");
|
||||
String userEmailNav = tinyDB.getString("userEmail");
|
||||
String userFullNameNav = tinyDB.getString("userFullname");
|
||||
String userAvatarNav = tinyDB.getString("userAvatar");
|
||||
|
||||
blurView = hView.findViewById(R.id.blurView);
|
||||
userEmail = hView.findViewById(R.id.userEmail);
|
||||
@ -252,17 +260,18 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
userAccountsList.addAll(userAccounts);
|
||||
navRecyclerViewUserAccounts.setAdapter(adapterUserAccounts);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
userEmail.setTypeface(myTypeface);
|
||||
userFullName.setTypeface(myTypeface);
|
||||
|
||||
if(!userEmailNav.equals("")) {
|
||||
|
||||
userEmail.setText(userEmailNav);
|
||||
}
|
||||
|
||||
if(!userFullNameNav.equals("")) {
|
||||
|
||||
userFullName.setText(userFullNameNav);
|
||||
}
|
||||
|
||||
@ -291,14 +300,11 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
.setBlurAlgorithm(new RenderScriptBlur(ctx))
|
||||
.setBlurRadius(5)
|
||||
.setHasFixedTransformationMatrix(false);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
userAvatar.setOnClickListener(v -> {
|
||||
@ -309,9 +315,13 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
drawer.closeDrawers();
|
||||
});
|
||||
|
||||
String currentVersion = tinyDb.getString("giteaVersion");
|
||||
getNotificationsCount(instanceToken);
|
||||
}
|
||||
|
||||
navigationView.getMenu().findItem(R.id.nav_administration).setVisible(tinyDb.getBoolean("userIsAdmin"));
|
||||
@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"));
|
||||
}
|
||||
|
||||
@ -333,98 +343,128 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
String launchFragmentByHandler = mainIntent.getStringExtra("launchFragmentByLinkHandler");
|
||||
|
||||
if(launchFragmentByHandler != null) {
|
||||
|
||||
mainIntent.removeExtra("launchFragmentByLinkHandler");
|
||||
|
||||
switch(launchFragmentByHandler) {
|
||||
|
||||
case "repos":
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new RepositoriesFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_repositories);
|
||||
return;
|
||||
case "org":
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new OrganizationsFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_organizations);
|
||||
return;
|
||||
case "notification":
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_notifications);
|
||||
return;
|
||||
case "explore":
|
||||
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_explore);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(savedInstanceState == null) {
|
||||
|
||||
if(!new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.3")) {
|
||||
if(!new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.3")) {
|
||||
|
||||
if(tinyDb.getInt("homeScreenId") == 7) {
|
||||
if(tinyDB.getInt("homeScreenId") == 7) {
|
||||
|
||||
tinyDb.putInt("homeScreenId", 0);
|
||||
tinyDB.putInt("homeScreenId", 0);
|
||||
}
|
||||
}
|
||||
|
||||
switch(tinyDb.getInt("homeScreenId")) {
|
||||
switch(tinyDB.getInt("homeScreenId")) {
|
||||
|
||||
case 1:
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new StarredRepositoriesFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_starred_repos);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new OrganizationsFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_organizations);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleRepositories));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new RepositoriesFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_repositories);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ProfileFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_profile);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreFragment()).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();
|
||||
navigationView.setCheckedItem(R.id.nav_home);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(!connToInternet) {
|
||||
|
||||
if(!tinyDb.getBoolean("noConnection")) {
|
||||
if(!tinyDB.getBoolean("noConnection")) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
}
|
||||
|
||||
tinyDb.putBoolean("noConnection", true);
|
||||
|
||||
tinyDB.putBoolean("noConnection", true);
|
||||
}
|
||||
else {
|
||||
|
||||
loadUserInfo(instanceUrl, instanceToken, loginUid);
|
||||
giteaVersion(instanceUrl);
|
||||
tinyDb.putBoolean("noConnection", false);
|
||||
|
||||
loadUserInfo(instanceToken, loginUid);
|
||||
giteaVersion();
|
||||
tinyDB.putBoolean("noConnection", false);
|
||||
}
|
||||
|
||||
// Changelog popup
|
||||
@ -440,10 +480,10 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
Log.e("changelogDialog", Objects.requireNonNull(e.getMessage()));
|
||||
}
|
||||
|
||||
if(versionCode > tinyDb.getInt("versionCode")) {
|
||||
if(versionCode > tinyDB.getInt("versionCode")) {
|
||||
|
||||
tinyDb.putInt("versionCode", versionCode);
|
||||
tinyDb.putBoolean("versionFlag", true);
|
||||
tinyDB.putInt("versionCode", versionCode);
|
||||
tinyDB.putBoolean("versionFlag", true);
|
||||
|
||||
ChangeLog changelogDialog = new ChangeLog(this);
|
||||
changelogDialog.showDialog();
|
||||
@ -458,7 +498,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
@Override
|
||||
public void onButtonClicked(String text) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(ctx);
|
||||
TinyDB tinyDb = TinyDB.getInstance(ctx);
|
||||
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||
|
||||
if("deleteDrafts".equals(text)) {
|
||||
@ -482,14 +522,15 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
|
||||
})
|
||||
.setNeutralButton(R.string.cancelButton, null).show();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.genericError));
|
||||
}
|
||||
|
||||
@ -501,74 +542,74 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
public void onBackPressed() {
|
||||
|
||||
if(drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
}
|
||||
else {
|
||||
|
||||
super.onBackPressed();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
|
||||
|
||||
switch(menuItem.getItemId()) {
|
||||
int id = menuItem.getItemId();
|
||||
|
||||
case R.id.nav_home:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyRepositoriesFragment()).commit();
|
||||
break;
|
||||
if(id == R.id.nav_home) {
|
||||
|
||||
case R.id.nav_organizations:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new OrganizationsFragment()).commit();
|
||||
break;
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MyRepositoriesFragment()).commit();
|
||||
}
|
||||
else if(id == R.id.nav_organizations) {
|
||||
|
||||
case R.id.nav_profile:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ProfileFragment()).commit();
|
||||
break;
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new OrganizationsFragment()).commit();
|
||||
}
|
||||
else if(id == R.id.nav_profile) {
|
||||
|
||||
case R.id.nav_repositories:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleRepositories));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new RepositoriesFragment()).commit();
|
||||
break;
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleProfile));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ProfileFragment()).commit();
|
||||
}
|
||||
else if(id == R.id.nav_repositories) {
|
||||
|
||||
case R.id.nav_settings:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleSettings));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit();
|
||||
break;
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleRepositories));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new RepositoriesFragment()).commit();
|
||||
}
|
||||
else if(id == R.id.nav_settings) {
|
||||
|
||||
case R.id.nav_logout:
|
||||
logout(this, ctx);
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
||||
break;
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleSettings));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new SettingsFragment()).commit();
|
||||
}
|
||||
else if(id == R.id.nav_logout) {
|
||||
|
||||
case R.id.nav_starred_repos:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new StarredRepositoriesFragment()).commit();
|
||||
break;
|
||||
logout(this, ctx);
|
||||
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
|
||||
}
|
||||
else if(id == R.id.nav_starred_repos) {
|
||||
|
||||
case R.id.nav_explore:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreFragment()).commit();
|
||||
break;
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new StarredRepositoriesFragment()).commit();
|
||||
}
|
||||
else if(id == R.id.nav_explore) {
|
||||
|
||||
case R.id.nav_notifications:
|
||||
toolbarTitle.setText(R.string.pageTitleNotifications);
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
|
||||
break;
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleExplore));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new ExploreFragment()).commit();
|
||||
}
|
||||
else if(id == R.id.nav_notifications) {
|
||||
|
||||
case R.id.nav_comments_draft:
|
||||
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new DraftsFragment()).commit();
|
||||
break;
|
||||
toolbarTitle.setText(R.string.pageTitleNotifications);
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new NotificationsFragment()).commit();
|
||||
}
|
||||
else if(id == R.id.nav_comments_draft) {
|
||||
|
||||
case R.id.nav_administration:
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleAdministration));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AdministrationFragment()).commit();
|
||||
break;
|
||||
toolbarTitle.setText(getResources().getString(R.string.titleDrafts));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new DraftsFragment()).commit();
|
||||
}
|
||||
else if(id == R.id.nav_administration) {
|
||||
|
||||
toolbarTitle.setText(getResources().getString(R.string.pageTitleAdministration));
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new AdministrationFragment()).commit();
|
||||
}
|
||||
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
@ -577,14 +618,14 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
|
||||
public static void logout(Activity activity, Context ctx) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(ctx.getApplicationContext());
|
||||
tinyDb.putBoolean("loggedInMode", false);
|
||||
tinyDb.remove("basicAuthPassword");
|
||||
tinyDb.putBoolean("basicAuthFlag", false);
|
||||
TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||
|
||||
tinyDB.putBoolean("loggedInMode", false);
|
||||
tinyDB.remove("basicAuthPassword");
|
||||
tinyDB.putBoolean("basicAuthFlag", false);
|
||||
//tinyDb.clear();
|
||||
activity.finish();
|
||||
ctx.startActivity(new Intent(ctx, LoginActivity.class));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -593,22 +634,22 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
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) {
|
||||
private void giteaVersion() {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
|
||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||
|
||||
Call<GiteaVersion> callVersion = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getGiteaVersionWithToken(token);
|
||||
Call<GiteaVersion> callVersion = RetrofitClient.getApiInterface(ctx).getGiteaVersionWithToken(token);
|
||||
|
||||
callVersion.enqueue(new Callback<GiteaVersion>() {
|
||||
|
||||
@ -621,7 +662,6 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
assert version != null;
|
||||
|
||||
tinyDb.putString("giteaVersion", version.getVersion());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -630,16 +670,14 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
|
||||
Log.e("onFailure-version", t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void loadUserInfo(String instanceUrl, String token, String loginUid) {
|
||||
private void loadUserInfo(String token, String loginUid) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
|
||||
Call<UserInfo> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserInfo(Authorization.returnAuthentication(ctx, loginUid, token));
|
||||
Call<UserInfo> call = RetrofitClient.getApiInterface(ctx).getUserInfo(Authorization.get(ctx));
|
||||
|
||||
call.enqueue(new Callback<UserInfo>() {
|
||||
|
||||
@ -655,6 +693,7 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
assert userDetails != null;
|
||||
|
||||
if(userDetails.getIs_admin() != null) {
|
||||
|
||||
tinyDb.putBoolean("userIsAdmin", userDetails.getIs_admin());
|
||||
}
|
||||
|
||||
@ -662,9 +701,11 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
tinyDb.putInt("userId", userDetails.getId());
|
||||
|
||||
if(!userDetails.getFullname().equals("")) {
|
||||
|
||||
tinyDb.putString("userFullname", userDetails.getFullname());
|
||||
}
|
||||
else {
|
||||
|
||||
tinyDb.putString("userFullname", userDetails.getLogin());
|
||||
}
|
||||
|
||||
@ -672,9 +713,11 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
tinyDb.putString("userAvatar", userDetails.getAvatar());
|
||||
|
||||
if(userDetails.getLang() != null) {
|
||||
|
||||
tinyDb.putString("userLang", userDetails.getLang());
|
||||
}
|
||||
else {
|
||||
|
||||
tinyDb.putString("userLang", "");
|
||||
}
|
||||
}
|
||||
@ -682,15 +725,12 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
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));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
String toastError = getResources().getString(R.string.genericApiStatusError) + response.code();
|
||||
Toasty.error(ctx, toastError);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -702,9 +742,9 @@ public class MainActivity extends BaseActivity implements NavigationView.OnNavig
|
||||
|
||||
}
|
||||
|
||||
private void getNotificationsCount(String instanceUrl, String token) {
|
||||
private void getNotificationsCount(String token) {
|
||||
|
||||
Call<NotificationCount> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkUnreadNotifications(token);
|
||||
Call<NotificationCount> call = RetrofitClient.getApiInterface(ctx).checkUnreadNotifications(token);
|
||||
|
||||
call.enqueue(new Callback<NotificationCount>() {
|
||||
|
||||
|
@ -6,30 +6,24 @@ import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import androidx.annotation.NonNull;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.hendraanggrian.appcompat.socialview.Mention;
|
||||
import com.hendraanggrian.appcompat.widget.MentionArrayAdapter;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -38,11 +32,13 @@ import retrofit2.Response;
|
||||
public class MergePullRequestActivity extends BaseActivity {
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
private String repoOwner;
|
||||
private String repoName;
|
||||
private int prIndex;
|
||||
|
||||
private ActivityMergePullRequestBinding viewBinding;
|
||||
|
||||
private ArrayAdapter<Mention> defaultMentionAdapter;
|
||||
private String Do;
|
||||
|
||||
@Override
|
||||
@ -56,14 +52,18 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
viewBinding = ActivityMergePullRequestBinding.inflate(getLayoutInflater());
|
||||
View view = viewBinding.getRoot();
|
||||
setContentView(view);
|
||||
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
repoOwner = parts[0];
|
||||
repoName = parts[1];
|
||||
prIndex = Integer.parseInt(tinyDB.getString("issueNumber"));
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
@ -73,53 +73,37 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
|
||||
setMergeAdapter();
|
||||
|
||||
viewBinding.mergeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
if(!tinyDB.getString("issueTitle").isEmpty()) {
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
|
||||
MergePullRequestSpinner mergeId = (MergePullRequestSpinner) parent.getSelectedItem();
|
||||
Do = mergeId.getId();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> parent) {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
defaultMentionAdapter = new MentionArrayAdapter<>(this);
|
||||
loadCollaboratorsList();
|
||||
|
||||
viewBinding.mergeDescription.setMentionAdapter(defaultMentionAdapter);
|
||||
|
||||
if(!tinyDb.getString("issueTitle").isEmpty()) {
|
||||
viewBinding.toolbarTitle.setText(tinyDb.getString("issueTitle"));
|
||||
viewBinding.mergeTitle.setText(tinyDb.getString("issueTitle") + " (#" + tinyDb.getString("issueNumber") + ")");
|
||||
viewBinding.toolbarTitle.setText(tinyDB.getString("issueTitle"));
|
||||
viewBinding.mergeTitle.setText(tinyDB.getString("issueTitle") + " (#" + tinyDB.getString("issueNumber") + ")");
|
||||
}
|
||||
|
||||
initCloseListener();
|
||||
viewBinding.close.setOnClickListener(onClickListener);
|
||||
|
||||
// if gitea version is greater/equal(1.12.0) than user installed version (installed.higherOrEqual(compareVer))
|
||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
|
||||
viewBinding.deleteBranch.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
if(tinyDb.getString("prMergeable").equals("false")) {
|
||||
if(tinyDB.getString("prMergeable").equals("false")) {
|
||||
|
||||
disableProcessButton();
|
||||
viewBinding.mergeInfoDisabledMessage.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
|
||||
viewBinding.mergeInfoDisabledMessage.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(tinyDb.getString("prIsFork").equals("true")) {
|
||||
if(tinyDB.getString("prIsFork").equals("true")) {
|
||||
|
||||
viewBinding.deleteBranchForkInfo.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
|
||||
viewBinding.deleteBranchForkInfo.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@ -136,70 +120,25 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
|
||||
private void setMergeAdapter() {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
ArrayList<MergePullRequestSpinner> mergeList = new ArrayList<>();
|
||||
|
||||
mergeList.add(new MergePullRequestSpinner("merge", getResources().getString(R.string.mergeOptionMerge)));
|
||||
mergeList.add(new MergePullRequestSpinner("rebase", getResources().getString(R.string.mergeOptionRebase)));
|
||||
mergeList.add(new MergePullRequestSpinner("rebase-merge", getResources().getString(R.string.mergeOptionRebaseCommit)));
|
||||
// squash merge works only on gitea > v1.11.4 due to a bug
|
||||
if(new Version(tinyDb.getString("giteaVersion")).higher("1.11.4")) {
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higher("1.11.4")) {
|
||||
|
||||
mergeList.add(new MergePullRequestSpinner("squash", getResources().getString(R.string.mergeOptionSquash)));
|
||||
}
|
||||
|
||||
ArrayAdapter<MergePullRequestSpinner> adapter = new ArrayAdapter<>(MergePullRequestActivity.this, R.layout.spinner_item, mergeList);
|
||||
adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
|
||||
ArrayAdapter<MergePullRequestSpinner> adapter = new ArrayAdapter<>(MergePullRequestActivity.this, R.layout.list_spinner_items, mergeList);
|
||||
viewBinding.mergeSpinner.setAdapter(adapter);
|
||||
|
||||
}
|
||||
|
||||
public void loadCollaboratorsList() {
|
||||
|
||||
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];
|
||||
|
||||
Call<List<Collaborators>> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<List<Collaborators>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
|
||||
|
||||
if(response.isSuccessful()) {
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Log.i("onResponse", String.valueOf(response.code()));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<List<Collaborators>> call, @NonNull Throwable t) {
|
||||
|
||||
Log.i("onFailure", t.toString());
|
||||
}
|
||||
viewBinding.mergeSpinner.setOnItemClickListener ((parent, view, position, id) -> {
|
||||
|
||||
Do = mergeList.get(position).getId();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
@ -207,12 +146,12 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
onClickListener = view -> finish();
|
||||
}
|
||||
|
||||
private View.OnClickListener mergePullRequest = v -> processMergePullRequest();
|
||||
private final View.OnClickListener mergePullRequest = v -> processMergePullRequest();
|
||||
|
||||
private void processMergePullRequest() {
|
||||
|
||||
String mergePRDesc = viewBinding.mergeDescription.getText().toString();
|
||||
String mergePRTitle = viewBinding.mergeTitle.getText().toString();
|
||||
String mergePRDesc = Objects.requireNonNull(viewBinding.mergeDescription.getText()).toString();
|
||||
String mergePRTitle = Objects.requireNonNull(viewBinding.mergeTitle.getText()).toString();
|
||||
boolean deleteBranch = viewBinding.deleteBranch.isChecked();
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
@ -221,30 +160,24 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
disableProcessButton();
|
||||
mergeFunction(Do, mergePRDesc, mergePRTitle, deleteBranch);
|
||||
if(Do == null) {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.selectMergeStrategy));
|
||||
}
|
||||
else {
|
||||
|
||||
disableProcessButton();
|
||||
mergeFunction(Do, mergePRDesc, mergePRTitle, deleteBranch);
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeFunction(String Do, String mergePRDT, String mergeTitle, boolean deleteBranch) {
|
||||
|
||||
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 prIndex = Integer.parseInt(tinyDb.getString("issueNumber"));
|
||||
|
||||
MergePullRequest mergePR = new MergePullRequest(Do, mergePRDT, mergeTitle);
|
||||
|
||||
Call<ResponseBody> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().mergePullRequest(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, prIndex, mergePR);
|
||||
Call<ResponseBody> call = RetrofitClient.getApiInterface(ctx).mergePullRequest(Authorization.get(ctx), repoOwner, repoName, prIndex, mergePR);
|
||||
|
||||
call.enqueue(new Callback<ResponseBody>() {
|
||||
|
||||
@ -255,9 +188,9 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
|
||||
if(deleteBranch) {
|
||||
|
||||
if(tinyDb.getString("prIsFork").equals("true")) {
|
||||
if(tinyDB.getString("prIsFork").equals("true")) {
|
||||
|
||||
String repoFullName = tinyDb.getString("prForkFullName");
|
||||
String repoFullName = tinyDB.getString("prForkFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
@ -265,14 +198,13 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
deleteBranchFunction(repoOwner, repoName);
|
||||
|
||||
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
||||
tinyDb.putBoolean("prMerged", true);
|
||||
tinyDb.putBoolean("resumePullRequests", true);
|
||||
tinyDB.putBoolean("prMerged", true);
|
||||
tinyDB.putBoolean("resumePullRequests", true);
|
||||
finish();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
@ -280,20 +212,18 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
deleteBranchFunction(repoOwner, repoName);
|
||||
|
||||
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
||||
tinyDb.putBoolean("prMerged", true);
|
||||
tinyDb.putBoolean("resumePullRequests", true);
|
||||
tinyDB.putBoolean("prMerged", true);
|
||||
tinyDB.putBoolean("resumePullRequests", true);
|
||||
finish();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.success(ctx, getString(R.string.mergePRSuccessMsg));
|
||||
tinyDb.putBoolean("prMerged", true);
|
||||
tinyDb.putBoolean("resumePullRequests", true);
|
||||
tinyDB.putBoolean("prMerged", true);
|
||||
tinyDB.putBoolean("resumePullRequests", true);
|
||||
finish();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -301,19 +231,21 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
|
||||
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.warning(ctx, getString(R.string.mergePR404ErrorMsg));
|
||||
}
|
||||
else if(response.code() == 405) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, getString(R.string.mergeNotAllowed));;
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.genericError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -331,17 +263,11 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
|
||||
private void deleteBranchFunction(String repoOwner, String repoName) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
String loginUid = tinyDb.getString("loginUid");
|
||||
String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
String branchName = tinyDb.getString("prHeadBranch");
|
||||
String branchName = tinyDB.getString("prHeadBranch");
|
||||
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.deleteBranch(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, branchName);
|
||||
.getApiInterface(ctx)
|
||||
.deleteBranch(Authorization.get(ctx), repoOwner, repoName, branchName);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@ -351,9 +277,7 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
if(response.code() == 204) {
|
||||
|
||||
Log.i("deleteBranch", "Branch deleted successfully");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -361,7 +285,6 @@ public class MergePullRequestActivity extends BaseActivity {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -25,8 +25,9 @@ public class OpenRepoInBrowserActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
appCtx = getApplicationContext();
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
|
||||
try {
|
||||
|
||||
@ -46,9 +47,9 @@ public class OpenRepoInBrowserActivity extends AppCompatActivity {
|
||||
|
||||
}
|
||||
catch(URISyntaxException e) {
|
||||
|
||||
Toasty.error(appCtx, getString(R.string.genericError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,9 +23,9 @@ import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.fragments.BottomSheetOrganizationFragment;
|
||||
import org.mian.gitnex.fragments.MembersByOrgFragment;
|
||||
import org.mian.gitnex.fragments.OrganizationInfoFragment;
|
||||
import org.mian.gitnex.fragments.OrganizationLabelsFragment;
|
||||
import org.mian.gitnex.fragments.RepositoriesByOrgFragment;
|
||||
import org.mian.gitnex.fragments.TeamsByOrgFragment;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import java.util.Objects;
|
||||
import io.mikael.urlbuilder.UrlBuilder;
|
||||
@ -36,10 +36,6 @@ import io.mikael.urlbuilder.UrlBuilder;
|
||||
|
||||
public class OrganizationDetailActivity extends BaseActivity implements BottomSheetOrganizationFragment.BottomSheetListener {
|
||||
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private TinyDB tinyDb;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_org_detail;
|
||||
@ -49,11 +45,8 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
tinyDb = new TinyDB(appCtx);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
String orgName = tinyDb.getString("orgName");
|
||||
String orgName = tinyDB.getString("orgName");
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
TextView toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
|
||||
@ -71,20 +64,20 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
||||
|
||||
Typeface myTypeface;
|
||||
|
||||
switch(tinyDb.getInt("customFontId", -1)) {
|
||||
switch(tinyDB.getInt("customFontId", -1)) {
|
||||
|
||||
case 0:
|
||||
|
||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/roboto.ttf");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/sourcecodeproregular.ttf");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/manroperegular.ttf");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
toolbarTitle.setTypeface(myTypeface);
|
||||
@ -92,12 +85,18 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
||||
|
||||
ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
|
||||
int tabsCount = vg.getChildCount();
|
||||
|
||||
for (int j = 0; j < tabsCount; j++) {
|
||||
|
||||
ViewGroup vgTab = (ViewGroup) vg.getChildAt(j);
|
||||
int tabChildCount = vgTab.getChildCount();
|
||||
|
||||
for (int i = 0; i < tabChildCount; i++) {
|
||||
|
||||
View tabViewChild = vgTab.getChildAt(i);
|
||||
|
||||
if (tabViewChild instanceof TextView) {
|
||||
|
||||
((TextView) tabViewChild).setTypeface(myTypeface);
|
||||
}
|
||||
}
|
||||
@ -105,7 +104,6 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
||||
|
||||
mViewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
|
||||
tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(mViewPager));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -122,18 +120,21 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
||||
|
||||
int id = item.getItemId();
|
||||
|
||||
switch (id) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.repoMenu:
|
||||
BottomSheetOrganizationFragment bottomSheet = new BottomSheetOrganizationFragment();
|
||||
bottomSheet.show(getSupportFragmentManager(), "orgBottomSheet");
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
if(id == android.R.id.home) {
|
||||
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
else if(id == R.id.repoMenu) {
|
||||
|
||||
BottomSheetOrganizationFragment bottomSheet = new BottomSheetOrganizationFragment();
|
||||
bottomSheet.show(getSupportFragmentManager(), "orgBottomSheet");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -142,20 +143,27 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
||||
switch (text) {
|
||||
case "repository":
|
||||
|
||||
tinyDb.putBoolean("organizationAction", true);
|
||||
tinyDB.putBoolean("organizationAction", true);
|
||||
startActivity(new Intent(OrganizationDetailActivity.this, CreateRepoActivity.class));
|
||||
break;
|
||||
case "label":
|
||||
|
||||
Intent intent = new Intent(ctx, CreateLabelActivity.class);
|
||||
intent.putExtra("orgName", getIntent().getStringExtra("orgName"));
|
||||
intent.putExtra("type", "org");
|
||||
ctx.startActivity(intent);
|
||||
break;
|
||||
case "team":
|
||||
|
||||
startActivity(new Intent(OrganizationDetailActivity.this, CreateTeamByOrgActivity.class));
|
||||
break;
|
||||
case "copyOrgUrl":
|
||||
|
||||
String url = UrlBuilder.fromString(tinyDb.getString("instanceUrl"))
|
||||
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"));
|
||||
ClipData clip = ClipData.newPlainText("orgUrl", url + tinyDB.getString("orgName"));
|
||||
assert clipboard != null;
|
||||
clipboard.setPrimaryClip(clip);
|
||||
Toasty.info(ctx, ctx.getString(R.string.copyIssueUrlToastMsg));
|
||||
@ -175,25 +183,34 @@ public class OrganizationDetailActivity extends BaseActivity implements BottomSh
|
||||
|
||||
String orgName;
|
||||
if(getIntent().getStringExtra("orgName") != null || !Objects.equals(getIntent().getStringExtra("orgName"), "")) {
|
||||
|
||||
orgName = getIntent().getStringExtra("orgName");
|
||||
}
|
||||
else {
|
||||
orgName = tinyDb.getString("orgName");
|
||||
|
||||
orgName = tinyDB.getString("orgName");
|
||||
}
|
||||
|
||||
Fragment fragment = null;
|
||||
switch (position) {
|
||||
|
||||
case 0: // info
|
||||
|
||||
return OrganizationInfoFragment.newInstance(orgName);
|
||||
case 1: // repos
|
||||
return RepositoriesByOrgFragment.newInstance(orgName);
|
||||
case 2: // teams
|
||||
|
||||
return RepositoriesByOrgFragment.newInstance(orgName);
|
||||
case 2: // labels
|
||||
|
||||
return OrganizationLabelsFragment.newInstance(orgName);
|
||||
case 3: // teams
|
||||
|
||||
return TeamsByOrgFragment.newInstance(orgName);
|
||||
case 3: // members
|
||||
case 4: // members
|
||||
|
||||
return MembersByOrgFragment.newInstance(orgName);
|
||||
}
|
||||
return fragment;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
@ -33,9 +32,6 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
||||
private GridView mGridView;
|
||||
private ProgressBar progressBar;
|
||||
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
private String teamId;
|
||||
|
||||
@Override
|
||||
@ -47,15 +43,10 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
||||
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");
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
TextView toolbarTitle = findViewById(R.id.toolbar_title);
|
||||
noDataMembers = findViewById(R.id.noDataMembers);
|
||||
@ -66,52 +57,55 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
if(getIntent().getStringExtra("teamTitle") != null && !Objects.requireNonNull(getIntent().getStringExtra("teamTitle")).equals("")) {
|
||||
toolbarTitle.setText(getIntent().getStringExtra("teamTitle"));
|
||||
|
||||
toolbarTitle.setText(getIntent().getStringExtra("teamTitle"));
|
||||
}
|
||||
else {
|
||||
toolbarTitle.setText(R.string.orgTeamMembers);
|
||||
|
||||
toolbarTitle.setText(R.string.orgTeamMembers);
|
||||
}
|
||||
|
||||
if(getIntent().getStringExtra("teamId") != null && !Objects.requireNonNull(getIntent().getStringExtra("teamId")).equals("")){
|
||||
teamId = getIntent().getStringExtra("teamId");
|
||||
|
||||
teamId = getIntent().getStringExtra("teamId");
|
||||
}
|
||||
else {
|
||||
teamId = "0";
|
||||
|
||||
teamId = "0";
|
||||
}
|
||||
|
||||
assert teamId != null;
|
||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), Integer.parseInt(teamId));
|
||||
|
||||
fetchDataAsync(Authorization.get(ctx), Integer.parseInt(teamId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
|
||||
super.onResume();
|
||||
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");
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
|
||||
if(tinyDb.getBoolean("teamActionFlag")) {
|
||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), Integer.parseInt(teamId));
|
||||
|
||||
fetchDataAsync(Authorization.get(ctx), Integer.parseInt(teamId));
|
||||
tinyDb.putBoolean("teamActionFlag", false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void fetchDataAsync(String instanceUrl, String instanceToken, int teamId) {
|
||||
private void fetchDataAsync(String instanceToken, int teamId) {
|
||||
|
||||
TeamMembersByOrgViewModel teamMembersModel = new ViewModelProvider(this).get(TeamMembersByOrgViewModel.class);
|
||||
|
||||
teamMembersModel.getMembersByOrgList(instanceUrl, instanceToken, teamId, ctx).observe(this, teamMembersListMain -> {
|
||||
teamMembersModel.getMembersByOrgList(instanceToken, teamId, ctx).observe(this, teamMembersListMain -> {
|
||||
|
||||
adapter = new TeamMembersByOrgAdapter(ctx, teamMembersListMain);
|
||||
|
||||
if(adapter.getCount() > 0) {
|
||||
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataMembers.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataMembers.setVisibility(View.VISIBLE);
|
||||
@ -119,7 +113,6 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
||||
|
||||
progressBar.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -128,7 +121,6 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.generic_nav_dotted_menu, menu);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -136,31 +128,32 @@ public class OrganizationTeamMembersActivity extends BaseActivity implements Bot
|
||||
|
||||
int id = item.getItemId();
|
||||
|
||||
switch(id) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
return true;
|
||||
case R.id.genericMenu:
|
||||
BottomSheetOrganizationTeamsFragment bottomSheet = new BottomSheetOrganizationTeamsFragment();
|
||||
bottomSheet.show(getSupportFragmentManager(), "orgTeamsBottomSheet");
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
if(id == android.R.id.home) {
|
||||
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
else if(id == R.id.genericMenu) {
|
||||
|
||||
BottomSheetOrganizationTeamsFragment bottomSheet = new BottomSheetOrganizationTeamsFragment();
|
||||
bottomSheet.show(getSupportFragmentManager(), "orgTeamsBottomSheet");
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onButtonClicked(String text) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
if("newMember".equals(text)) {
|
||||
|
||||
Intent intent = new Intent(OrganizationTeamMembersActivity.this, AddNewTeamMemberActivity.class);
|
||||
intent.putExtra("teamId", teamId);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
|
@ -33,8 +33,6 @@ public class ProfileEmailActivity extends BaseActivity {
|
||||
|
||||
private View.OnClickListener onClickListener;
|
||||
private EditText userEmail;
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private Button addEmailButton;
|
||||
|
||||
@Override
|
||||
@ -46,7 +44,6 @@ public class ProfileEmailActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
|
||||
@ -73,19 +70,11 @@ public class ProfileEmailActivity extends BaseActivity {
|
||||
|
||||
}
|
||||
|
||||
private View.OnClickListener addEmailListener = new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
processAddNewEmail();
|
||||
}
|
||||
};
|
||||
private final View.OnClickListener addEmailListener = v -> processAddNewEmail();
|
||||
|
||||
private void processAddNewEmail() {
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
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 newUserEmail = userEmail.getText().toString().trim();
|
||||
|
||||
@ -93,39 +82,34 @@ public class ProfileEmailActivity extends BaseActivity {
|
||||
|
||||
Toasty.error(ctx, getResources().getString(R.string.checkNetConnection));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
if(newUserEmail.equals("")) {
|
||||
|
||||
Toasty.error(ctx, getString(R.string.emailErrorEmpty));
|
||||
return;
|
||||
|
||||
}
|
||||
else if(!Patterns.EMAIL_ADDRESS.matcher(newUserEmail).matches()) {
|
||||
|
||||
Toasty.warning(ctx, getString(R.string.emailErrorInvalid));
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
List<String> newEmailList = new ArrayList<>(Arrays.asList(newUserEmail.split(",")));
|
||||
|
||||
disableProcessButton();
|
||||
addNewEmail(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), newEmailList);
|
||||
|
||||
addNewEmail(Authorization.get(ctx), newEmailList);
|
||||
}
|
||||
|
||||
private void addNewEmail(final String instanceUrl, final String token, List<String> newUserEmail) {
|
||||
private void addNewEmail(final String token, List<String> newUserEmail) {
|
||||
|
||||
AddEmail addEmailFunc = new AddEmail(newUserEmail);
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(appCtx)
|
||||
.addNewEmail(token, addEmailFunc);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
@ -139,7 +123,6 @@ public class ProfileEmailActivity extends BaseActivity {
|
||||
tinyDb.putBoolean("emailsRefresh", true);
|
||||
enableProcessButton();
|
||||
finish();
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
@ -148,37 +131,32 @@ public class ProfileEmailActivity extends BaseActivity {
|
||||
getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
|
||||
}
|
||||
else if(response.code() == 404) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||
|
||||
}
|
||||
else if(response.code() == 422) {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.warning(ctx, ctx.getString(R.string.emailErrorInUse));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
enableProcessButton();
|
||||
Toasty.error(ctx, getString(R.string.labelGeneralError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||
|
||||
Log.e("onFailure", t.toString());
|
||||
enableProcessButton();
|
||||
}
|
||||
|
@ -1,430 +0,0 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
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 java.util.List;
|
||||
import java.util.Objects;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class ReplyToIssueActivity extends BaseActivity {
|
||||
|
||||
public ImageView closeActivity;
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
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
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
boolean connToInternet = AppUtil.hasNetworkConnection(appCtx);
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
draftSaved = findViewById(R.id.draftSaved);
|
||||
addComment = findViewById(R.id.addComment);
|
||||
addComment.setShowSoftInputOnFocus(true);
|
||||
|
||||
defaultMentionAdapter = new MentionArrayAdapter<>(ctx);
|
||||
loadCollaboratorsList();
|
||||
|
||||
addComment.setMentionAdapter(defaultMentionAdapter);
|
||||
|
||||
closeActivity = findViewById(R.id.close);
|
||||
TextView toolbar_title = findViewById(R.id.toolbar_title);
|
||||
|
||||
addComment.requestFocus();
|
||||
assert imm != null;
|
||||
imm.showSoftInput(addComment, InputMethodManager.SHOW_IMPLICIT);
|
||||
|
||||
if(!tinyDb.getString("issueTitle").isEmpty()) {
|
||||
toolbar_title.setText(tinyDb.getString("issueTitle"));
|
||||
}
|
||||
|
||||
initCloseListener();
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
if(getIntent().getStringExtra("draftId") != null) {
|
||||
|
||||
draftIdOnCreate = Long.parseLong(Objects.requireNonNull(getIntent().getStringExtra("draftId")));
|
||||
}
|
||||
else {
|
||||
|
||||
if(getIntent().getStringExtra("commentBody") != null) {
|
||||
draftIdOnCreate = returnDraftId(getIntent().getStringExtra("commentBody"));
|
||||
}
|
||||
else {
|
||||
draftIdOnCreate = returnDraftId("");
|
||||
}
|
||||
}
|
||||
|
||||
replyButton = findViewById(R.id.replyButton);
|
||||
|
||||
if(getIntent().getStringExtra("commentBody") != null) {
|
||||
|
||||
addComment.setText(getIntent().getStringExtra("commentBody"));
|
||||
|
||||
if(getIntent().getBooleanExtra("cursorToEnd", false)) {
|
||||
addComment.setSelection(addComment.length());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(getIntent().getStringExtra("draftTitle") != null) {
|
||||
|
||||
toolbar_title.setText(getIntent().getStringExtra("draftTitle"));
|
||||
|
||||
}
|
||||
|
||||
if(getIntent().getStringExtra("commentAction") != null && Objects.equals(getIntent().getStringExtra("commentAction"), "edit") && !Objects.equals(getIntent().getStringExtra("commentId"), "new")) {
|
||||
|
||||
final String commentId = getIntent().getStringExtra("commentId");
|
||||
|
||||
toolbar_title.setText(getResources().getString(R.string.editCommentTitle));
|
||||
replyButton.setText(getResources().getString(R.string.editCommentButtonText));
|
||||
|
||||
addComment.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
saveDraft(addComment.getText().toString(), commentId, draftIdOnCreate);
|
||||
draftSaved.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
replyButton.setOnClickListener(v -> {
|
||||
|
||||
disableProcessButton();
|
||||
assert commentId != null;
|
||||
IssueActions.editIssueComment(ctx, Integer.parseInt(commentId), addComment.getText().toString(), draftIdOnCreate);
|
||||
|
||||
});
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
addComment.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
}
|
||||
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
saveDraft(addComment.getText().toString(), "new", draftIdOnCreate);
|
||||
draftSaved.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
if(!connToInternet) {
|
||||
|
||||
disableProcessButton();
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
replyButton.setOnClickListener(replyToIssue);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void saveDraft(String draftText, String commentId, long draftIdOnCreate) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||
|
||||
int repositoryId = (int) tinyDb.getLong("repositoryId", 0);
|
||||
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||
int issueNumber = Integer.parseInt(tinyDb.getString("issueNumber"));
|
||||
|
||||
DraftsApi draftsApi = new DraftsApi(appCtx);
|
||||
|
||||
if(draftIdOnCreate == 0) {
|
||||
|
||||
draftsApi.insertDraft(repositoryId, currentActiveAccountId, issueNumber, draftText, StaticGlobalVariables.draftTypeComment, commentId);
|
||||
}
|
||||
else {
|
||||
|
||||
DraftsApi.updateDraft(draftText, (int) draftIdOnCreate, commentId); //updateDraftByIssueIdAsyncTask(draftText, issueNumber, repositoryId, commentId);
|
||||
}
|
||||
}
|
||||
|
||||
private long returnDraftId(String draftText) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getApplicationContext());
|
||||
|
||||
int repositoryId = (int) tinyDb.getLong("repositoryId", 0);
|
||||
int currentActiveAccountId = tinyDb.getInt("currentActiveAccountId");
|
||||
int issueNumber = Integer.parseInt(tinyDb.getString("issueNumber"));
|
||||
|
||||
DraftsApi draftsApi = new DraftsApi(appCtx);
|
||||
|
||||
return draftsApi.insertDraft(repositoryId, currentActiveAccountId, issueNumber, draftText, StaticGlobalVariables.draftTypeComment, "");
|
||||
|
||||
}
|
||||
|
||||
public void loadCollaboratorsList() {
|
||||
|
||||
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];
|
||||
|
||||
Call<List<Collaborators>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getCollaborators(Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<List<Collaborators>>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<List<Collaborators>> call, @NonNull Response<List<Collaborators>> response) {
|
||||
|
||||
if (response.isSuccessful()) {
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -42,7 +42,6 @@ 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;
|
||||
@ -71,12 +70,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
private FragmentRefreshListenerMilestone fragmentRefreshListenerMilestone;
|
||||
private FragmentRefreshListenerFiles fragmentRefreshListenerFiles;
|
||||
|
||||
private final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
private TinyDB tinyDB;
|
||||
|
||||
private String instanceUrl;
|
||||
private String loginUid;
|
||||
private String instanceToken;
|
||||
|
||||
@ -96,9 +89,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
tinyDB = new TinyDB(appCtx);
|
||||
|
||||
String[] repoNameParts = tinyDB.getString("repoFullName").split("/");
|
||||
repositoryOwner = repoNameParts[0];
|
||||
@ -113,7 +103,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
Objects.requireNonNull(getSupportActionBar()).setTitle(repositoryName);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
instanceUrl = tinyDB.getString("instanceUrl");
|
||||
loginUid = tinyDB.getString("loginUid");
|
||||
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||
|
||||
@ -126,17 +115,17 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
switch(tinyDB.getInt("customFontId", -1)) {
|
||||
|
||||
case 0:
|
||||
|
||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/roboto.ttf");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
|
||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/sourcecodeproregular.ttf");
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
myTypeface = Typeface.createFromAsset(ctx.getAssets(), "fonts/manroperegular.ttf");
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
toolbarTitle.setTypeface(myTypeface);
|
||||
@ -156,6 +145,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
View tabViewChild = vgTab.getChildAt(i);
|
||||
|
||||
if(tabViewChild instanceof TextView) {
|
||||
|
||||
((TextView) tabViewChild).setTypeface(myTypeface);
|
||||
}
|
||||
}
|
||||
@ -172,7 +162,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
|
||||
tabsCount--;
|
||||
collaboratorTab.setVisibility(View.GONE);
|
||||
|
||||
}
|
||||
|
||||
mViewPager = findViewById(R.id.container);
|
||||
@ -198,7 +187,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
textViewBadgePull.setVisibility(View.GONE);
|
||||
textViewBadgeRelease.setVisibility(View.GONE);
|
||||
|
||||
getRepoInfo(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repositoryOwner, repositoryName);
|
||||
getRepoInfo(Authorization.get(ctx), repositoryOwner, repositoryName);
|
||||
ColorStateList textColor = tabLayout.getTabTextColors();
|
||||
|
||||
// Issue count
|
||||
@ -209,7 +198,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
assert tabOpenIssues != null; // FIXME This should be cleaned up
|
||||
TextView openIssueTabView = Objects.requireNonNull(tabOpenIssues.getCustomView()).findViewById(R.id.counterBadgeIssueText);
|
||||
openIssueTabView.setTextColor(textColor);
|
||||
|
||||
}
|
||||
|
||||
// Pull request count
|
||||
@ -220,7 +208,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
assert tabOpenPulls != null; // FIXME This should be cleaned up
|
||||
TextView openPullTabView = Objects.requireNonNull(tabOpenPulls.getCustomView()).findViewById(R.id.counterBadgePullText);
|
||||
openPullTabView.setTextColor(textColor);
|
||||
|
||||
}
|
||||
|
||||
// Release count
|
||||
@ -233,14 +220,31 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
assert tabOpenRelease != null; // FIXME This should be cleaned up
|
||||
TextView openReleaseTabView = Objects.requireNonNull(tabOpenRelease.getCustomView()).findViewById(R.id.counterBadgeReleaseText);
|
||||
openReleaseTabView.setTextColor(textColor);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkRepositoryStarStatus(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repositoryOwner, repositoryName);
|
||||
checkRepositoryWatchStatus(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repositoryOwner, repositoryName);
|
||||
Intent mainIntent = getIntent();
|
||||
String goToSection = mainIntent.getStringExtra("goToSection");
|
||||
String goToSectionType = mainIntent.getStringExtra("goToSectionType");
|
||||
|
||||
if(goToSection != null) {
|
||||
|
||||
mainIntent.removeExtra("goToSection");
|
||||
mainIntent.removeExtra("goToSectionType");
|
||||
|
||||
if(goToSectionType.equals("issue")) {
|
||||
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(2);
|
||||
}
|
||||
else if(goToSectionType.equals("pull")) {
|
||||
|
||||
RepoDetailActivity.mViewPager.setCurrentItem(3);
|
||||
}
|
||||
}
|
||||
|
||||
checkRepositoryStarStatus(Authorization.get(ctx), repositoryOwner, repositoryName);
|
||||
checkRepositoryWatchStatus(Authorization.get(ctx), repositoryOwner, repositoryName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -250,9 +254,8 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
|
||||
if(tinyDB.getBoolean("enableCounterIssueBadge")) {
|
||||
|
||||
getRepoInfo(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repositoryOwner, repositoryName);
|
||||
getRepoInfo(Authorization.get(ctx), repositoryOwner, repositoryName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -261,7 +264,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
MenuInflater inflater = getMenuInflater();
|
||||
inflater.inflate(R.menu.repo_dotted_menu, menu);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -318,106 +320,111 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
switch(text) {
|
||||
|
||||
case "label":
|
||||
|
||||
startActivity(new Intent(RepoDetailActivity.this, CreateLabelActivity.class));
|
||||
break;
|
||||
|
||||
case "newIssue":
|
||||
|
||||
startActivity(new Intent(RepoDetailActivity.this, CreateIssueActivity.class));
|
||||
break;
|
||||
|
||||
case "newMilestone":
|
||||
|
||||
startActivity(new Intent(RepoDetailActivity.this, CreateMilestoneActivity.class));
|
||||
break;
|
||||
|
||||
case "addCollaborator":
|
||||
|
||||
startActivity(new Intent(RepoDetailActivity.this, AddCollaboratorToRepositoryActivity.class));
|
||||
break;
|
||||
|
||||
case "chooseBranch":
|
||||
|
||||
chooseBranch();
|
||||
break;
|
||||
|
||||
case "createRelease":
|
||||
|
||||
startActivity(new Intent(RepoDetailActivity.this, CreateReleaseActivity.class));
|
||||
break;
|
||||
|
||||
case "openWebRepo":
|
||||
|
||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(tinyDB.getString("repoHtmlUrl")));
|
||||
startActivity(i);
|
||||
break;
|
||||
|
||||
case "shareRepo":
|
||||
|
||||
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||||
sharingIntent.setType("text/plain");
|
||||
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, tinyDB.getString("repoHtmlUrl"));
|
||||
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, tinyDB.getString("repoHtmlUrl"));
|
||||
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;
|
||||
|
||||
case "openIssues":
|
||||
|
||||
if(getFragmentRefreshListener() != null) {
|
||||
|
||||
getFragmentRefreshListener().onRefresh("open");
|
||||
}
|
||||
break;
|
||||
|
||||
case "closedIssues":
|
||||
|
||||
if(getFragmentRefreshListener() != null) {
|
||||
|
||||
getFragmentRefreshListener().onRefresh("closed");
|
||||
}
|
||||
break;
|
||||
|
||||
case "openPr":
|
||||
|
||||
if(getFragmentRefreshListenerPr() != null) {
|
||||
|
||||
getFragmentRefreshListenerPr().onRefresh("open");
|
||||
}
|
||||
break;
|
||||
|
||||
case "closedPr":
|
||||
|
||||
if(getFragmentRefreshListenerPr() != null) {
|
||||
|
||||
getFragmentRefreshListenerPr().onRefresh("closed");
|
||||
}
|
||||
break;
|
||||
|
||||
case "openMilestone":
|
||||
|
||||
if(getFragmentRefreshListenerMilestone() != null) {
|
||||
|
||||
getFragmentRefreshListenerMilestone().onRefresh("open");
|
||||
}
|
||||
break;
|
||||
|
||||
case "closedMilestone":
|
||||
|
||||
if(getFragmentRefreshListenerMilestone() != null) {
|
||||
|
||||
getFragmentRefreshListenerMilestone().onRefresh("closed");
|
||||
}
|
||||
break;
|
||||
|
||||
case "repoSettings":
|
||||
|
||||
startActivity(new Intent(RepoDetailActivity.this, RepositorySettingsActivity.class));
|
||||
break;
|
||||
|
||||
case "newPullRequest":
|
||||
|
||||
startActivity(new Intent(RepoDetailActivity.this, CreatePullRequestActivity.class));
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void chooseBranch() {
|
||||
|
||||
Call<List<Branches>> call = RetrofitClient.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
Call<List<Branches>> call = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.getBranches(instanceToken, repositoryOwner, repositoryName);
|
||||
|
||||
call.enqueue(new Callback<List<Branches>>() {
|
||||
@ -451,7 +458,9 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
|
||||
tinyDB.putString("repoBranch", branchesList.get(i));
|
||||
|
||||
if(getFragmentRefreshListenerFiles() != null) {
|
||||
|
||||
getFragmentRefreshListenerFiles().onRefresh(branchesList.get(i));
|
||||
}
|
||||
dialogInterface.dismiss();
|
||||
@ -460,9 +469,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
pBuilder.setNeutralButton(R.string.cancelButton, null);
|
||||
|
||||
pBuilder.create().show();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -490,37 +497,36 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
switch(position) {
|
||||
|
||||
case 0: // Repository details
|
||||
|
||||
return RepoInfoFragment.newInstance(repositoryOwner, repositoryName);
|
||||
|
||||
case 1: // Files
|
||||
return FilesFragment.newInstance(repositoryOwner, repositoryName, tinyDB.getString("repoBranch"));
|
||||
|
||||
return FilesFragment.newInstance(repositoryOwner, repositoryName, tinyDB.getString("repoBranch"));
|
||||
case 2: // Issues
|
||||
|
||||
fragment = new IssuesFragment();
|
||||
break;
|
||||
|
||||
case 3: // Pull requests
|
||||
|
||||
fragment = new PullRequestsFragment();
|
||||
break;
|
||||
|
||||
case 4: // Releases
|
||||
return ReleasesFragment.newInstance(repositoryOwner, repositoryName);
|
||||
|
||||
return ReleasesFragment.newInstance(repositoryOwner, repositoryName);
|
||||
case 5: // Milestones
|
||||
|
||||
fragment = new MilestonesFragment();
|
||||
break;
|
||||
|
||||
case 6: // Labels
|
||||
|
||||
return LabelsFragment.newInstance(repositoryOwner, repositoryName);
|
||||
|
||||
case 7: // Collaborators
|
||||
return CollaboratorsFragment.newInstance(repositoryOwner, repositoryName);
|
||||
|
||||
return CollaboratorsFragment.newInstance(repositoryOwner, repositoryName);
|
||||
}
|
||||
|
||||
assert fragment != null;
|
||||
return fragment;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -528,12 +534,11 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
|
||||
return tabsCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void getRepoInfo(String instanceUrl, String token, final String owner, String repo) {
|
||||
private void getRepoInfo(String token, final String owner, String repo) {
|
||||
|
||||
Call<UserRepositories> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().getUserRepository(token, owner, repo);
|
||||
Call<UserRepositories> call = RetrofitClient.getApiInterface(ctx).getUserRepository(token, owner, repo);
|
||||
call.enqueue(new Callback<UserRepositories>() {
|
||||
|
||||
@Override
|
||||
@ -544,6 +549,7 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
if(response.code() == 200) {
|
||||
|
||||
if(tinyDB.getBoolean("enableCounterBadges")) {
|
||||
|
||||
assert repoInfo != null;
|
||||
|
||||
if(repoInfo.getOpen_issues_count() != null) {
|
||||
@ -570,7 +576,6 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
|
||||
Log.e("onFailure", String.valueOf(response.code()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -583,16 +588,15 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
|
||||
}
|
||||
|
||||
private void checkRepositoryStarStatus(String instanceUrl, String instanceToken, final String owner, String repo) {
|
||||
private void checkRepositoryStarStatus(String instanceToken, final String owner, String repo) {
|
||||
|
||||
Call<JsonElement> call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkRepoStarStatus(instanceToken, owner, repo);
|
||||
Call<JsonElement> call = RetrofitClient.getApiInterface(ctx).checkRepoStarStatus(instanceToken, owner, repo);
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||
|
||||
tinyDB.putInt("repositoryStarStatus", response.code());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -604,11 +608,11 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
|
||||
}
|
||||
|
||||
private void checkRepositoryWatchStatus(String instanceUrl, String instanceToken, final String owner, String repo) {
|
||||
private void checkRepositoryWatchStatus(String instanceToken, final String owner, String repo) {
|
||||
|
||||
Call<WatchInfo> call;
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, ctx).getApiInterface().checkRepoWatchStatus(instanceToken, owner, repo);
|
||||
call = RetrofitClient.getApiInterface(ctx).checkRepoWatchStatus(instanceToken, owner, repo);
|
||||
call.enqueue(new Callback<WatchInfo>() {
|
||||
|
||||
@Override
|
||||
@ -619,15 +623,14 @@ public class RepoDetailActivity extends BaseActivity implements BottomSheetRepoF
|
||||
assert response.body() != null;
|
||||
|
||||
if(response.body().getSubscribed()) {
|
||||
|
||||
tinyDB.putBoolean("repositoryWatchStatus", true);
|
||||
}
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
tinyDB.putBoolean("repositoryWatchStatus", false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -42,8 +41,6 @@ import retrofit2.Response;
|
||||
|
||||
public class RepoForksActivity extends BaseActivity {
|
||||
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
private View.OnClickListener onClickListener;
|
||||
private TextView noData;
|
||||
private ProgressBar progressBar;
|
||||
@ -67,14 +64,11 @@ public class RepoForksActivity extends BaseActivity {
|
||||
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");
|
||||
TinyDB tinyDb = TinyDB.getInstance(appCtx);
|
||||
|
||||
String repoFullNameForForks = getIntent().getStringExtra("repoFullNameForForks");
|
||||
assert repoFullNameForForks != null;
|
||||
@ -97,6 +91,7 @@ public class RepoForksActivity extends BaseActivity {
|
||||
|
||||
// if gitea is 1.12 or higher use the new limit (resultLimitNewGiteaInstances)
|
||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12")) {
|
||||
|
||||
resultLimit = StaticGlobalVariables.resultLimitNewGiteaInstances;
|
||||
}
|
||||
|
||||
@ -110,7 +105,7 @@ public class RepoForksActivity extends BaseActivity {
|
||||
swipeRefresh.setOnRefreshListener(() -> new Handler(Looper.getMainLooper()).postDelayed(() -> {
|
||||
|
||||
swipeRefresh.setRefreshing(false);
|
||||
loadInitial(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, pageSize, resultLimit);
|
||||
loadInitial(Authorization.get(ctx), repoOwner, repoName, pageSize, resultLimit);
|
||||
adapter.notifyDataChanged();
|
||||
|
||||
}, 200));
|
||||
@ -121,25 +116,21 @@ public class RepoForksActivity extends BaseActivity {
|
||||
if(forksList.size() == resultLimit || pageSize == resultLimit) {
|
||||
|
||||
int page = (forksList.size() + resultLimit) / resultLimit;
|
||||
loadMore(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName, page, resultLimit);
|
||||
|
||||
loadMore(Authorization.get(ctx), 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);
|
||||
|
||||
loadInitial(Authorization.get(ctx), repoOwner, repoName, pageSize, resultLimit);
|
||||
}
|
||||
|
||||
private void loadInitial(String instanceUrl, String instanceToken, String repoOwner, String repoName, int pageSize, int resultLimit) {
|
||||
private void loadInitial(String instanceToken, String repoOwner, String repoName, int pageSize, int resultLimit) {
|
||||
|
||||
Call<List<UserRepositories>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.getRepositoryForks(instanceToken, repoOwner, repoName, pageSize, resultLimit);
|
||||
|
||||
call.enqueue(new Callback<List<UserRepositories>>() {
|
||||
@ -150,29 +141,27 @@ public class RepoForksActivity extends BaseActivity {
|
||||
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
|
||||
@ -180,18 +169,16 @@ public class RepoForksActivity extends BaseActivity {
|
||||
|
||||
Log.e(TAG, t.toString());
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void loadMore(String instanceUrl, String instanceToken, String repoOwner, String repoName, int page, int resultLimit) {
|
||||
private void loadMore(String instanceToken, String repoOwner, String repoName, int page, int resultLimit) {
|
||||
|
||||
progressLoadMore.setVisibility(View.VISIBLE);
|
||||
|
||||
Call<List<UserRepositories>> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.getRepositoryForks(instanceToken, repoOwner, repoName, page, resultLimit);
|
||||
|
||||
call.enqueue(new Callback<List<UserRepositories>>() {
|
||||
@ -205,37 +192,31 @@ public class RepoForksActivity extends BaseActivity {
|
||||
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());
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
@ -270,7 +251,6 @@ public class RepoForksActivity extends BaseActivity {
|
||||
});
|
||||
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
|
||||
}
|
||||
|
||||
private void filter(String text) {
|
||||
@ -278,7 +258,9 @@ public class RepoForksActivity extends BaseActivity {
|
||||
List<UserRepositories> arr = new ArrayList<>();
|
||||
|
||||
for(UserRepositories d : forksList) {
|
||||
|
||||
if(d.getName().toLowerCase().contains(text) || d.getDescription().toLowerCase().contains(text)) {
|
||||
|
||||
arr.add(d);
|
||||
}
|
||||
}
|
||||
@ -289,6 +271,7 @@ public class RepoForksActivity extends BaseActivity {
|
||||
private void initCloseListener() {
|
||||
|
||||
onClickListener = view -> {
|
||||
|
||||
getIntent().removeExtra("repoFullNameForForks");
|
||||
finish();
|
||||
};
|
||||
|
@ -1,22 +1,16 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
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.viewmodels.RepoStargazersViewModel;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -30,9 +24,6 @@ public class RepoStargazersActivity extends BaseActivity {
|
||||
private GridView mGridView;
|
||||
private ProgressBar mProgressBar;
|
||||
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_repo_stargazers;
|
||||
@ -42,12 +33,6 @@ public class RepoStargazersActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
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");
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
TextView toolbarTitle = findViewById(R.id.toolbar_title);
|
||||
@ -65,29 +50,30 @@ public class RepoStargazersActivity extends BaseActivity {
|
||||
|
||||
toolbarTitle.setText(R.string.repoStargazersInMenu);
|
||||
|
||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
||||
|
||||
fetchDataAsync(Authorization.get(ctx), repoOwner, repoName);
|
||||
}
|
||||
|
||||
private void fetchDataAsync(String instanceUrl, String instanceToken, String repoOwner, String repoName) {
|
||||
private void fetchDataAsync(String instanceToken, String repoOwner, String repoName) {
|
||||
|
||||
RepoStargazersViewModel repoStargazersModel = new ViewModelProvider(this).get(RepoStargazersViewModel.class);
|
||||
|
||||
repoStargazersModel.getRepoStargazers(instanceUrl, instanceToken, repoOwner, repoName, ctx).observe(this, new Observer<List<UserInfo>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<UserInfo> stargazersListMain) {
|
||||
adapter = new RepoStargazersAdapter(ctx, stargazersListMain);
|
||||
if(adapter.getCount() > 0) {
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataStargazers.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
adapter.notifyDataSetChanged();
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataStargazers.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
repoStargazersModel.getRepoStargazers(instanceToken, repoOwner, repoName, ctx).observe(this, stargazersListMain -> {
|
||||
|
||||
adapter = new RepoStargazersAdapter(ctx, stargazersListMain);
|
||||
|
||||
if(adapter.getCount() > 0) {
|
||||
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataStargazers.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataStargazers.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -1,22 +1,16 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
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.viewmodels.RepoWatchersViewModel;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -30,9 +24,6 @@ public class RepoWatchersActivity extends BaseActivity {
|
||||
private GridView mGridView;
|
||||
private ProgressBar mProgressBar;
|
||||
|
||||
final Context ctx = this;
|
||||
private Context appCtx;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId(){
|
||||
return R.layout.activity_repo_watchers;
|
||||
@ -42,12 +33,6 @@ public class RepoWatchersActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
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");
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
TextView toolbarTitle = findViewById(R.id.toolbar_title);
|
||||
@ -65,29 +50,30 @@ public class RepoWatchersActivity extends BaseActivity {
|
||||
|
||||
toolbarTitle.setText(R.string.repoWatchersInMenu);
|
||||
|
||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(ctx, loginUid, instanceToken), repoOwner, repoName);
|
||||
|
||||
fetchDataAsync(Authorization.get(ctx), repoOwner, repoName);
|
||||
}
|
||||
|
||||
private void fetchDataAsync(String instanceUrl, String instanceToken, String repoOwner, String repoName) {
|
||||
private void fetchDataAsync(String instanceToken, String repoOwner, String repoName) {
|
||||
|
||||
RepoWatchersViewModel repoWatchersModel = new ViewModelProvider(this).get(RepoWatchersViewModel.class);
|
||||
|
||||
repoWatchersModel.getRepoWatchers(instanceUrl, instanceToken, repoOwner, repoName, ctx).observe(this, new Observer<List<UserInfo>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<UserInfo> watchersListMain) {
|
||||
adapter = new RepoWatchersAdapter(ctx, watchersListMain);
|
||||
if(adapter.getCount() > 0) {
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataWatchers.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
adapter.notifyDataSetChanged();
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataWatchers.setVisibility(View.VISIBLE);
|
||||
}
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
repoWatchersModel.getRepoWatchers(instanceToken, repoOwner, repoName, ctx).observe(this, watchersListMain -> {
|
||||
|
||||
adapter = new RepoWatchersAdapter(ctx, watchersListMain);
|
||||
|
||||
if(adapter.getCount() > 0) {
|
||||
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataWatchers.setVisibility(View.GONE);
|
||||
}
|
||||
else {
|
||||
|
||||
adapter.notifyDataSetChanged();
|
||||
mGridView.setAdapter(adapter);
|
||||
noDataWatchers.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
mProgressBar.setVisibility(View.GONE);
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
@ -18,7 +17,6 @@ import org.mian.gitnex.databinding.ActivityRepositorySettingsBinding;
|
||||
import org.mian.gitnex.databinding.CustomRepositoryDeleteDialogBinding;
|
||||
import org.mian.gitnex.databinding.CustomRepositoryEditPropertiesDialogBinding;
|
||||
import org.mian.gitnex.databinding.CustomRepositoryTransferDialogBinding;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.Version;
|
||||
import org.mian.gitnex.models.RepositoryTransfer;
|
||||
@ -40,11 +38,7 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
private Dialog dialogDeleteRepository;
|
||||
private Dialog dialogTransferRepository;
|
||||
private View.OnClickListener onClickListener;
|
||||
private Context ctx = this;
|
||||
private Context appCtx;
|
||||
private TinyDB tinyDb;
|
||||
|
||||
private String instanceUrl;
|
||||
private String loginUid;
|
||||
private String instanceToken;
|
||||
|
||||
@ -60,20 +54,17 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
tinyDb = new TinyDB(appCtx);
|
||||
|
||||
viewBinding = ActivityRepositorySettingsBinding.inflate(getLayoutInflater());
|
||||
View view = viewBinding.getRoot();
|
||||
setContentView(view);
|
||||
|
||||
instanceUrl = tinyDb.getString("instanceUrl");
|
||||
loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
loginUid = tinyDB.getString("loginUid");
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
repositoryOwner = parts[0];
|
||||
repositoryName = parts[1];
|
||||
instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
|
||||
@ -81,23 +72,16 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
// require gitea 1.12 or higher
|
||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.0")) {
|
||||
|
||||
viewBinding.transferOwnerFrame.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
viewBinding.editProperties.setOnClickListener(editProperties -> {
|
||||
showRepositoryProperties();
|
||||
});
|
||||
viewBinding.editProperties.setOnClickListener(editProperties -> showRepositoryProperties());
|
||||
|
||||
viewBinding.deleteRepository.setOnClickListener(deleteRepository -> {
|
||||
showDeleteRepository();
|
||||
});
|
||||
|
||||
viewBinding.transferOwnerFrame.setOnClickListener(transferRepositoryOwnership -> {
|
||||
showTransferRepository();
|
||||
});
|
||||
viewBinding.deleteRepository.setOnClickListener(deleteRepository -> showDeleteRepository());
|
||||
|
||||
viewBinding.transferOwnerFrame.setOnClickListener(transferRepositoryOwnership -> showTransferRepository());
|
||||
}
|
||||
|
||||
private void showTransferRepository() {
|
||||
@ -114,9 +98,7 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
View view = transferRepoBinding.getRoot();
|
||||
dialogTransferRepository.setContentView(view);
|
||||
|
||||
transferRepoBinding.cancel.setOnClickListener(editProperties -> {
|
||||
dialogTransferRepository.dismiss();
|
||||
});
|
||||
transferRepoBinding.cancel.setOnClickListener(editProperties -> dialogTransferRepository.dismiss());
|
||||
|
||||
transferRepoBinding.transfer.setOnClickListener(deleteRepo -> {
|
||||
|
||||
@ -145,8 +127,7 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
RepositoryTransfer repositoryTransfer = new RepositoryTransfer(newOwner);
|
||||
|
||||
Call<JsonElement> transferCall = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.transferRepository(instanceToken, repositoryOwner, repositoryName, repositoryTransfer);
|
||||
|
||||
transferCall.enqueue(new Callback<JsonElement>() {
|
||||
@ -163,7 +144,7 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
Toasty.success(ctx, getString(R.string.repoTransferSuccess));
|
||||
|
||||
finish();
|
||||
RepositoriesApi.deleteRepository((int) tinyDb.getLong("repositoryId", 0));
|
||||
RepositoriesApi.deleteRepository((int) tinyDB.getLong("repositoryId", 0));
|
||||
Intent intent = new Intent(RepositorySettingsActivity.this, MainActivity.class);
|
||||
RepositorySettingsActivity.this.startActivity(intent);
|
||||
}
|
||||
@ -197,6 +178,7 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
dialogDeleteRepository = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||
|
||||
if (dialogDeleteRepository.getWindow() != null) {
|
||||
|
||||
dialogDeleteRepository.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
}
|
||||
|
||||
@ -205,9 +187,7 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
View view = deleteRepoBinding.getRoot();
|
||||
dialogDeleteRepository.setContentView(view);
|
||||
|
||||
deleteRepoBinding.cancel.setOnClickListener(editProperties -> {
|
||||
dialogDeleteRepository.dismiss();
|
||||
});
|
||||
deleteRepoBinding.cancel.setOnClickListener(editProperties -> dialogDeleteRepository.dismiss());
|
||||
|
||||
deleteRepoBinding.delete.setOnClickListener(deleteRepo -> {
|
||||
|
||||
@ -227,8 +207,7 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
private void deleteRepository() {
|
||||
|
||||
Call<JsonElement> deleteCall = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.deleteRepository(instanceToken, repositoryOwner, repositoryName);
|
||||
|
||||
deleteCall.enqueue(new Callback<JsonElement>() {
|
||||
@ -245,7 +224,7 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
Toasty.success(ctx, getString(R.string.repoDeletionSuccess));
|
||||
|
||||
finish();
|
||||
RepositoriesApi.deleteRepository((int) tinyDb.getLong("repositoryId", 0));
|
||||
RepositoriesApi.deleteRepository((int) tinyDB.getLong("repositoryId", 0));
|
||||
Intent intent = new Intent(RepositorySettingsActivity.this, MainActivity.class);
|
||||
RepositorySettingsActivity.this.startActivity(intent);
|
||||
}
|
||||
@ -273,6 +252,7 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
dialogProp = new Dialog(ctx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||
|
||||
if (dialogProp.getWindow() != null) {
|
||||
|
||||
dialogProp.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
|
||||
}
|
||||
|
||||
@ -281,13 +261,10 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
View view = propBinding.getRoot();
|
||||
dialogProp.setContentView(view);
|
||||
|
||||
propBinding.cancel.setOnClickListener(editProperties -> {
|
||||
dialogProp.dismiss();
|
||||
});
|
||||
propBinding.cancel.setOnClickListener(editProperties -> dialogProp.dismiss());
|
||||
|
||||
Call<UserRepositories> call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.getUserRepository(instanceToken, repositoryOwner, repositoryName);
|
||||
|
||||
call.enqueue(new Callback<UserRepositories>() {
|
||||
@ -314,19 +291,24 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
propBinding.repoEnableIssues.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
if (isChecked) {
|
||||
|
||||
propBinding.repoEnableTimer.setVisibility(View.VISIBLE);
|
||||
}
|
||||
else {
|
||||
|
||||
propBinding.repoEnableTimer.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
if(repoInfo.getInternal_tracker() != null) {
|
||||
|
||||
propBinding.repoEnableTimer.setChecked(repoInfo.getInternal_tracker().isEnable_time_tracker());
|
||||
}
|
||||
else {
|
||||
|
||||
propBinding.repoEnableTimer.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
propBinding.repoEnableWiki.setChecked(repoInfo.isHas_wiki());
|
||||
propBinding.repoEnablePr.setChecked(repoInfo.isHas_pull_requests());
|
||||
propBinding.repoEnableMerge.setChecked(repoInfo.isAllow_merge_commits());
|
||||
@ -359,7 +341,6 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
propBinding.repoEnableSquash.isChecked(), propBinding.repoEnableForceMerge.isChecked()));
|
||||
|
||||
dialogProp.show();
|
||||
|
||||
}
|
||||
|
||||
private void saveRepositoryProperties(String repoName, String repoWebsite, String repoDescription,
|
||||
@ -370,18 +351,20 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
UserRepositories.internalTimeTrackerObject repoPropsTimeTracker = new UserRepositories.internalTimeTrackerObject(repoEnableTimer);
|
||||
|
||||
UserRepositories repoProps;
|
||||
|
||||
if(!repoEnableIssues) {
|
||||
|
||||
repoProps = new UserRepositories(repoName, repoWebsite, repoDescription, repoPrivate, repoAsTemplate, repoEnableIssues, repoEnableWiki, repoEnablePr, repoEnableMerge,
|
||||
repoEnableRebase, repoEnableSquash, repoEnableForceMerge);
|
||||
}
|
||||
else {
|
||||
|
||||
repoProps = new UserRepositories(repoName, repoWebsite, repoDescription, repoPrivate, repoAsTemplate, repoEnableIssues, repoEnableWiki, repoEnablePr, repoPropsTimeTracker, repoEnableMerge,
|
||||
repoEnableRebase, repoEnableSquash, repoEnableForceMerge);
|
||||
}
|
||||
|
||||
Call<UserRepositories> propsCall = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
.getApiInterface(ctx)
|
||||
.updateRepositoryProperties(instanceToken, repositoryOwner, repositoryName, repoProps);
|
||||
|
||||
propsCall.enqueue(new Callback<UserRepositories>() {
|
||||
@ -394,8 +377,8 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
|
||||
if (response.code() == 200) {
|
||||
|
||||
tinyDb.putBoolean("hasIssues", repoEnableIssues);
|
||||
tinyDb.putBoolean("hasPullRequests", repoEnablePr);
|
||||
tinyDB.putBoolean("hasIssues", repoEnableIssues);
|
||||
tinyDB.putBoolean("hasPullRequests", repoEnablePr);
|
||||
|
||||
dialogProp.dismiss();
|
||||
Toasty.success(ctx, getString(R.string.repoPropertiesSaveSuccess));
|
||||
@ -403,10 +386,9 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
if(!repositoryName.equals(repoName)) {
|
||||
|
||||
finish();
|
||||
RepositoriesApi.updateRepositoryOwnerAndName(repositoryOwner, repoName, (int) tinyDb.getLong("repositoryId", 0));
|
||||
RepositoriesApi.updateRepositoryOwnerAndName(repositoryOwner, repoName, (int) tinyDB.getLong("repositoryId", 0));
|
||||
Intent intent = new Intent(RepositorySettingsActivity.this, MainActivity.class);
|
||||
RepositorySettingsActivity.this.startActivity(intent);
|
||||
|
||||
}
|
||||
}
|
||||
else {
|
||||
@ -415,7 +397,6 @@ public class RepositorySettingsActivity extends BaseActivity {
|
||||
propBinding.processingRequest.setVisibility(View.GONE);
|
||||
Toasty.error(ctx, getString(R.string.genericError));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,17 +1,14 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.google.android.material.switchmaterial.SwitchMaterial;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.Version;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -19,23 +16,15 @@ import org.mian.gitnex.helpers.Version;
|
||||
|
||||
public class SettingsAppearanceActivity extends BaseActivity {
|
||||
|
||||
private Context appCtx;
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
private static String[] timeList = {"Pretty", "Normal"};
|
||||
private static final String[] timeList = {"Pretty", "Normal"};
|
||||
private static int timeSelectedChoice = 0;
|
||||
|
||||
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", "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"};
|
||||
private static final String[] customFontList = {"Roboto", "Manrope", "Source Code Pro"};
|
||||
private static int customFontSelectedChoice = 0;
|
||||
|
||||
private static String[] themeList = {"Dark", "Light", "Auto (Light / Dark)", "Retro", "Auto (Retro / Dark)"};
|
||||
private static final String[] themeList = {"Dark", "Light", "Auto (Light / Dark)", "Retro", "Auto (Retro / Dark)", "Pitch Black"};
|
||||
private static int themeSelectedChoice = 0;
|
||||
|
||||
@Override
|
||||
@ -48,93 +37,59 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
|
||||
final TextView tvDateTimeSelected = findViewById(R.id.tvDateTimeSelected); // setter for time
|
||||
final TextView codeBlockSelected = findViewById(R.id.codeBlockSelected); // setter for code block
|
||||
final TextView homeScreenSelected = findViewById(R.id.homeScreenSelected); // setter for home screen
|
||||
final TextView customFontSelected = findViewById(R.id.customFontSelected); // setter for custom font
|
||||
final TextView themeSelected = findViewById(R.id.themeSelected); // setter for theme
|
||||
|
||||
LinearLayout timeFrame = findViewById(R.id.timeFrame);
|
||||
LinearLayout codeBlockFrame = findViewById(R.id.codeBlockFrame);
|
||||
LinearLayout homeScreenFrame = findViewById(R.id.homeScreenFrame);
|
||||
LinearLayout customFontFrame = findViewById(R.id.customFontFrame);
|
||||
LinearLayout themeFrame = findViewById(R.id.themeSelectionFrame);
|
||||
|
||||
Switch counterBadgesSwitch = findViewById(R.id.switchCounterBadge);
|
||||
SwitchMaterial counterBadgesSwitch = findViewById(R.id.switchCounterBadge);
|
||||
|
||||
initCloseListener();
|
||||
closeActivity.setOnClickListener(onClickListener);
|
||||
|
||||
if(new Version(tinyDb.getString("giteaVersion")).higherOrEqual("1.12.3")) {
|
||||
if(!tinyDB.getString("timeStr").isEmpty()) {
|
||||
|
||||
homeScreenList = homeScreenListNew;
|
||||
tvDateTimeSelected.setText(tinyDB.getString("timeStr"));
|
||||
}
|
||||
|
||||
if(!tinyDb.getString("timeStr").isEmpty()) {
|
||||
tvDateTimeSelected.setText(tinyDb.getString("timeStr"));
|
||||
if(!tinyDB.getString("customFontStr").isEmpty()) {
|
||||
|
||||
customFontSelected.setText(tinyDB.getString("customFontStr"));
|
||||
}
|
||||
|
||||
if(!tinyDb.getString("codeBlockStr").isEmpty()) {
|
||||
codeBlockSelected.setText(tinyDb.getString("codeBlockStr"));
|
||||
}
|
||||
if(!tinyDB.getString("themeStr").isEmpty()) {
|
||||
|
||||
if(!tinyDb.getString("homeScreenStr").isEmpty()) {
|
||||
homeScreenSelected.setText(tinyDb.getString("homeScreenStr"));
|
||||
}
|
||||
|
||||
if(!tinyDb.getString("customFontStr").isEmpty()) {
|
||||
customFontSelected.setText(tinyDb.getString("customFontStr"));
|
||||
}
|
||||
|
||||
if(!tinyDb.getString("themeStr").isEmpty()) {
|
||||
themeSelected.setText(tinyDb.getString("themeStr"));
|
||||
themeSelected.setText(tinyDB.getString("themeStr"));
|
||||
}
|
||||
|
||||
if(timeSelectedChoice == 0) {
|
||||
timeSelectedChoice = tinyDb.getInt("timeId");
|
||||
}
|
||||
|
||||
if(codeBlockSelectedChoice == 0) {
|
||||
codeBlockSelectedChoice = tinyDb.getInt("codeBlockId");
|
||||
}
|
||||
|
||||
if(homeScreenSelectedChoice == 0) {
|
||||
homeScreenSelectedChoice = tinyDb.getInt("homeScreenId");
|
||||
timeSelectedChoice = tinyDB.getInt("timeId");
|
||||
}
|
||||
|
||||
if(customFontSelectedChoice == 0) {
|
||||
customFontSelectedChoice = tinyDb.getInt("customFontId", 1);
|
||||
|
||||
customFontSelectedChoice = tinyDB.getInt("customFontId", 1);
|
||||
}
|
||||
|
||||
if(themeSelectedChoice == 0) {
|
||||
themeSelectedChoice = tinyDb.getInt("themeId");
|
||||
|
||||
themeSelectedChoice = tinyDB.getInt("themeId");
|
||||
}
|
||||
|
||||
if(tinyDb.getBoolean("enableCounterBadges")) {
|
||||
counterBadgesSwitch.setChecked(true);
|
||||
}
|
||||
else {
|
||||
counterBadgesSwitch.setChecked(false);
|
||||
}
|
||||
counterBadgesSwitch.setChecked(tinyDB.getBoolean("enableCounterBadges"));
|
||||
|
||||
// counter badge switcher
|
||||
counterBadgesSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
if (isChecked) {
|
||||
tinyDb.putBoolean("enableCounterBadges", true);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
}
|
||||
else {
|
||||
tinyDb.putBoolean("enableCounterBadges", false);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
}
|
||||
|
||||
tinyDB.putBoolean("enableCounterBadges", isChecked);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
// theme selection dialog
|
||||
@ -143,31 +98,24 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
||||
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
||||
|
||||
tsBuilder.setTitle(getResources().getString(R.string.themeSelectorDialogTitle));
|
||||
if(themeSelectedChoice != -1) {
|
||||
tsBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
tsBuilder.setCancelable(false);
|
||||
}
|
||||
tsBuilder.setCancelable(themeSelectedChoice != -1);
|
||||
|
||||
tsBuilder.setSingleChoiceItems(themeList, themeSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||
|
||||
themeSelectedChoice = i;
|
||||
themeSelected.setText(themeList[i]);
|
||||
tinyDb.putString("themeStr", themeList[i]);
|
||||
tinyDb.putInt("themeId", i);
|
||||
tinyDB.putString("themeStr", themeList[i]);
|
||||
tinyDB.putInt("themeId", i);
|
||||
|
||||
tinyDb.putBoolean("refreshParent", true);
|
||||
tinyDB.putBoolean("refreshParent", true);
|
||||
this.recreate();
|
||||
this.overridePendingTransition(0, 0);
|
||||
dialogInterfaceTheme.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
AlertDialog cfDialog = tsBuilder.create();
|
||||
cfDialog.show();
|
||||
|
||||
});
|
||||
|
||||
// custom font dialog
|
||||
@ -176,114 +124,24 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
||||
AlertDialog.Builder cfBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
||||
|
||||
cfBuilder.setTitle(R.string.settingsCustomFontSelectorDialogTitle);
|
||||
if(customFontSelectedChoice != -1) {
|
||||
cfBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
cfBuilder.setCancelable(false);
|
||||
}
|
||||
cfBuilder.setCancelable(customFontSelectedChoice != -1);
|
||||
|
||||
cfBuilder.setSingleChoiceItems(customFontList, customFontSelectedChoice, (dialogInterfaceCustomFont, i) -> {
|
||||
|
||||
customFontSelectedChoice = i;
|
||||
customFontSelected.setText(customFontList[i]);
|
||||
tinyDb.putString("customFontStr", customFontList[i]);
|
||||
tinyDb.putInt("customFontId", i);
|
||||
tinyDB.putString("customFontStr", customFontList[i]);
|
||||
tinyDB.putInt("customFontId", i);
|
||||
|
||||
tinyDb.putBoolean("refreshParent", true);
|
||||
tinyDB.putBoolean("refreshParent", true);
|
||||
this.recreate();
|
||||
this.overridePendingTransition(0, 0);
|
||||
dialogInterfaceCustomFont.dismiss();
|
||||
Toasty.success(appCtx, appCtx.getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
AlertDialog cfDialog = cfBuilder.create();
|
||||
cfDialog.show();
|
||||
|
||||
});
|
||||
|
||||
// home screen dialog
|
||||
homeScreenFrame.setOnClickListener(view -> {
|
||||
|
||||
AlertDialog.Builder hsBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
||||
|
||||
hsBuilder.setTitle(R.string.settingsHomeScreenSelectorDialogTitle);
|
||||
if(homeScreenSelectedChoice != -1) {
|
||||
hsBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
hsBuilder.setCancelable(false);
|
||||
}
|
||||
|
||||
hsBuilder.setSingleChoiceItems(homeScreenList, homeScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> {
|
||||
|
||||
homeScreenSelectedChoice = i;
|
||||
homeScreenSelected.setText(homeScreenList[i]);
|
||||
tinyDb.putString("homeScreenStr", homeScreenList[i]);
|
||||
tinyDb.putInt("homeScreenId", i);
|
||||
|
||||
dialogInterfaceHomeScreen.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
AlertDialog hsDialog = hsBuilder.create();
|
||||
hsDialog.show();
|
||||
|
||||
});
|
||||
|
||||
// code block dialog
|
||||
codeBlockFrame.setOnClickListener(view -> {
|
||||
|
||||
AlertDialog.Builder cBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
||||
|
||||
cBuilder.setTitle(R.string.settingsCodeBlockSelectorDialogTitle);
|
||||
if(codeBlockSelectedChoice != -1) {
|
||||
cBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
cBuilder.setCancelable(false);
|
||||
}
|
||||
|
||||
cBuilder.setSingleChoiceItems(codeBlockList, codeBlockSelectedChoice, (dialogInterfaceCodeBlock, i) -> {
|
||||
|
||||
codeBlockSelectedChoice = i;
|
||||
codeBlockSelected.setText(codeBlockList[i]);
|
||||
tinyDb.putString("codeBlockStr", codeBlockList[i]);
|
||||
tinyDb.putInt("codeBlockId", i);
|
||||
|
||||
switch(codeBlockList[i]) {
|
||||
case "White - Black":
|
||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorWhite));
|
||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
|
||||
break;
|
||||
case "Grey - Black":
|
||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorAccent));
|
||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
|
||||
break;
|
||||
case "White - Grey":
|
||||
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.colorWhite));
|
||||
break;
|
||||
default:
|
||||
tinyDb.putInt("codeBlockColor", getResources().getColor(R.color.colorLightGreen));
|
||||
tinyDb.putInt("codeBlockBackground", getResources().getColor(R.color.black));
|
||||
break;
|
||||
}
|
||||
|
||||
dialogInterfaceCodeBlock.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
AlertDialog cDialog = cBuilder.create();
|
||||
cDialog.show();
|
||||
|
||||
});
|
||||
|
||||
// time and date dialog
|
||||
@ -292,36 +150,30 @@ public class SettingsAppearanceActivity extends BaseActivity {
|
||||
AlertDialog.Builder tBuilder = new AlertDialog.Builder(SettingsAppearanceActivity.this);
|
||||
|
||||
tBuilder.setTitle(R.string.settingsTimeSelectorDialogTitle);
|
||||
if(timeSelectedChoice != -1) {
|
||||
tBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
tBuilder.setCancelable(false);
|
||||
}
|
||||
tBuilder.setCancelable(timeSelectedChoice != -1);
|
||||
|
||||
tBuilder.setSingleChoiceItems(timeList, timeSelectedChoice, (dialogInterfaceTime, i) -> {
|
||||
|
||||
timeSelectedChoice = i;
|
||||
tvDateTimeSelected.setText(timeList[i]);
|
||||
tinyDb.putString("timeStr", timeList[i]);
|
||||
tinyDb.putInt("timeId", i);
|
||||
tinyDB.putString("timeStr", timeList[i]);
|
||||
tinyDB.putInt("timeId", i);
|
||||
|
||||
if("Normal".equals(timeList[i])) {
|
||||
tinyDb.putString("dateFormat", "normal");
|
||||
|
||||
tinyDB.putString("dateFormat", "normal");
|
||||
}
|
||||
else {
|
||||
tinyDb.putString("dateFormat", "pretty");
|
||||
|
||||
tinyDB.putString("dateFormat", "pretty");
|
||||
}
|
||||
|
||||
dialogInterfaceTime.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
AlertDialog tDialog = tBuilder.create();
|
||||
tDialog.show();
|
||||
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,11 @@
|
||||
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 com.google.android.material.switchmaterial.SwitchMaterial;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -15,7 +13,6 @@ import org.mian.gitnex.helpers.TinyDB;
|
||||
|
||||
public class SettingsDraftsActivity extends BaseActivity {
|
||||
|
||||
private Context appCtx;
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
@Override
|
||||
@ -28,36 +25,21 @@ public class SettingsDraftsActivity extends BaseActivity {
|
||||
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);
|
||||
SwitchMaterial commentsDeletionSwitch = findViewById(R.id.commentsDeletionSwitch);
|
||||
|
||||
if(tinyDb.getBoolean("draftsCommentsDeletionEnabled")) {
|
||||
commentsDeletionSwitch.setChecked(true);
|
||||
}
|
||||
else {
|
||||
commentsDeletionSwitch.setChecked(false);
|
||||
}
|
||||
commentsDeletionSwitch.setChecked(tinyDB.getBoolean("draftsCommentsDeletionEnabled"));
|
||||
|
||||
// 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));
|
||||
}
|
||||
|
||||
tinyDB.putBoolean("draftsCommentsDeletionEnabled", isChecked);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.google.android.material.switchmaterial.SwitchMaterial;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
|
||||
/**
|
||||
@ -18,10 +16,9 @@ import org.mian.gitnex.helpers.Toasty;
|
||||
|
||||
public class SettingsFileViewerActivity extends BaseActivity {
|
||||
|
||||
private Context appCtx;
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
private static String[] fileViewerSourceCodeThemesList = {"Sublime", "Arduino Light", "Github", "Far ", "Ir Black", "Android Studio"};
|
||||
private static final String[] fileViewerSourceCodeThemesList = {"Sublime", "Arduino Light", "Github", "Far ", "Ir Black", "Android Studio"};
|
||||
private static int fileViewerSourceCodeThemesSelectedChoice = 0;
|
||||
|
||||
@Override
|
||||
@ -34,9 +31,6 @@ public class SettingsFileViewerActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
|
||||
@ -47,22 +41,17 @@ public class SettingsFileViewerActivity extends BaseActivity {
|
||||
|
||||
LinearLayout sourceCodeThemeFrame = findViewById(R.id.sourceCodeThemeFrame);
|
||||
|
||||
Switch pdfModeSwitch = findViewById(R.id.switchPdfMode);
|
||||
SwitchMaterial pdfModeSwitch = findViewById(R.id.switchPdfMode);
|
||||
|
||||
if(!tinyDb.getString("fileviewerSourceCodeThemeStr").isEmpty()) {
|
||||
fileViewerSourceCodeThemesSelected.setText(tinyDb.getString("fileviewerSourceCodeThemeStr"));
|
||||
if(!tinyDB.getString("fileviewerSourceCodeThemeStr").isEmpty()) {
|
||||
fileViewerSourceCodeThemesSelected.setText(tinyDB.getString("fileviewerSourceCodeThemeStr"));
|
||||
}
|
||||
|
||||
if(fileViewerSourceCodeThemesSelectedChoice == 0) {
|
||||
fileViewerSourceCodeThemesSelectedChoice = tinyDb.getInt("fileviewerThemeId");
|
||||
fileViewerSourceCodeThemesSelectedChoice = tinyDB.getInt("fileviewerThemeId");
|
||||
}
|
||||
|
||||
if(tinyDb.getBoolean("enablePdfMode")) {
|
||||
pdfModeSwitch.setChecked(true);
|
||||
}
|
||||
else {
|
||||
pdfModeSwitch.setChecked(false);
|
||||
}
|
||||
pdfModeSwitch.setChecked(tinyDB.getBoolean("enablePdfMode"));
|
||||
|
||||
// fileviewer srouce code theme selection dialog
|
||||
sourceCodeThemeFrame.setOnClickListener(view -> {
|
||||
@ -70,19 +59,14 @@ public class SettingsFileViewerActivity extends BaseActivity {
|
||||
AlertDialog.Builder fvtsBuilder = new AlertDialog.Builder(SettingsFileViewerActivity.this);
|
||||
|
||||
fvtsBuilder.setTitle(R.string.fileviewerSourceCodeThemeSelectorDialogTitle);
|
||||
if(fileViewerSourceCodeThemesSelectedChoice != -1) {
|
||||
fvtsBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
fvtsBuilder.setCancelable(false);
|
||||
}
|
||||
fvtsBuilder.setCancelable(fileViewerSourceCodeThemesSelectedChoice != -1);
|
||||
|
||||
fvtsBuilder.setSingleChoiceItems(fileViewerSourceCodeThemesList, fileViewerSourceCodeThemesSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||
|
||||
fileViewerSourceCodeThemesSelectedChoice = i;
|
||||
fileViewerSourceCodeThemesSelected.setText(fileViewerSourceCodeThemesList[i]);
|
||||
tinyDb.putString("fileviewerSourceCodeThemeStr", fileViewerSourceCodeThemesList[i]);
|
||||
tinyDb.putInt("fileviewerSourceCodeThemeId", i);
|
||||
tinyDB.putString("fileviewerSourceCodeThemeStr", fileViewerSourceCodeThemesList[i]);
|
||||
tinyDB.putInt("fileviewerSourceCodeThemeId", i);
|
||||
|
||||
dialogInterfaceTheme.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
@ -91,25 +75,15 @@ public class SettingsFileViewerActivity extends BaseActivity {
|
||||
|
||||
AlertDialog cfDialog = fvtsBuilder.create();
|
||||
cfDialog.show();
|
||||
|
||||
});
|
||||
|
||||
// pdf night mode switcher
|
||||
pdfModeSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
if(isChecked) {
|
||||
tinyDb.putBoolean("enablePdfMode", true);
|
||||
tinyDb.putString("enablePdfModeInit", "yes");
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
}
|
||||
else {
|
||||
tinyDb.putBoolean("enablePdfMode", false);
|
||||
tinyDb.putString("enablePdfModeInit", "yes");
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
}
|
||||
|
||||
tinyDB.putBoolean("enablePdfMode", isChecked);
|
||||
tinyDB.putString("enablePdfModeInit", "yes");
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
|
@ -0,0 +1,176 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.databinding.ActivitySettingsGeneralBinding;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.Version;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class SettingsGeneralActivity extends BaseActivity {
|
||||
|
||||
private ActivitySettingsGeneralBinding viewBinding;
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
private List<String> homeScreenList;
|
||||
private static int homeScreenSelectedChoice = 0;
|
||||
|
||||
private List<String> defaultScreen;
|
||||
private static int defaultLinkHandlerScreenSelectedChoice = 0;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId() {
|
||||
|
||||
return R.layout.activity_settings_general;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
viewBinding = ActivitySettingsGeneralBinding.inflate(getLayoutInflater());
|
||||
View view = viewBinding.getRoot();
|
||||
setContentView(view);
|
||||
|
||||
initCloseListener();
|
||||
viewBinding.close.setOnClickListener(onClickListener);
|
||||
|
||||
// home screen
|
||||
String[] homeDefaultScreen_ = {getResources().getString(R.string.pageTitleMyRepos), getResources().getString(R.string.pageTitleStarredRepos), getResources().getString(R.string.pageTitleOrganizations),
|
||||
getResources().getString(R.string.pageTitleRepositories), getResources().getString(R.string.pageTitleProfile), getResources().getString(R.string.pageTitleExplore),
|
||||
getResources().getString(R.string.titleDrafts)};
|
||||
|
||||
String[] homeDefaultScreenNew = {getResources().getString(R.string.pageTitleMyRepos), getResources().getString(R.string.pageTitleStarredRepos), getResources().getString(R.string.pageTitleOrganizations),
|
||||
getResources().getString(R.string.pageTitleRepositories), getResources().getString(R.string.pageTitleProfile), getResources().getString(R.string.pageTitleExplore),
|
||||
getResources().getString(R.string.titleDrafts), getResources().getString(R.string.pageTitleNotifications)};
|
||||
|
||||
if(new Version(tinyDB.getString("giteaVersion")).higherOrEqual("1.12.3")) {
|
||||
|
||||
homeDefaultScreen_ = homeDefaultScreenNew;
|
||||
}
|
||||
|
||||
homeScreenList = new ArrayList<>(Arrays.asList(homeDefaultScreen_));
|
||||
String[] homeScreenArray = new String[homeScreenList.size()];
|
||||
homeScreenList.toArray(homeScreenArray);
|
||||
|
||||
if(homeScreenSelectedChoice == 0) {
|
||||
|
||||
homeScreenSelectedChoice = tinyDB.getInt("homeScreenId");
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleMyRepos));
|
||||
}
|
||||
|
||||
if(homeScreenSelectedChoice == 1) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleStarredRepos));
|
||||
}
|
||||
else if(homeScreenSelectedChoice == 2) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleOrganizations));
|
||||
}
|
||||
else if(homeScreenSelectedChoice == 3) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleRepositories));
|
||||
}
|
||||
else if(homeScreenSelectedChoice == 4) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleProfile));
|
||||
}
|
||||
else if(homeScreenSelectedChoice == 5) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleExplore));
|
||||
}
|
||||
else if(homeScreenSelectedChoice == 6) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.titleDrafts));
|
||||
}
|
||||
else if(homeScreenSelectedChoice == 7) {
|
||||
|
||||
viewBinding.homeScreenSelected.setText(getResources().getString(R.string.pageTitleNotifications));
|
||||
}
|
||||
|
||||
viewBinding.homeScreenFrame.setOnClickListener(setDefaultHomeScreen -> {
|
||||
|
||||
AlertDialog.Builder hsBuilder = new AlertDialog.Builder(SettingsGeneralActivity.this);
|
||||
|
||||
hsBuilder.setTitle(R.string.settingsHomeScreenSelectorDialogTitle);
|
||||
hsBuilder.setCancelable(homeScreenSelectedChoice != -1);
|
||||
|
||||
hsBuilder.setSingleChoiceItems(homeScreenArray, homeScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> {
|
||||
|
||||
homeScreenSelectedChoice = i;
|
||||
viewBinding.homeScreenSelected.setText(homeScreenArray[i]);
|
||||
tinyDB.putInt("homeScreenId", i);
|
||||
|
||||
dialogInterfaceHomeScreen.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
AlertDialog hsDialog = hsBuilder.create();
|
||||
hsDialog.show();
|
||||
});
|
||||
// home screen
|
||||
|
||||
// link handler
|
||||
String[] defaultScreen_ = {getResources().getString(R.string.generalDeepLinkSelectedText), getResources().getString(R.string.navRepos), getResources().getString(R.string.navOrgs), getResources().getString(R.string.pageTitleNotifications), getResources().getString(R.string.navExplore)};
|
||||
defaultScreen = new ArrayList<>(Arrays.asList(defaultScreen_));
|
||||
|
||||
String[] linksArray = new String[defaultScreen.size()];
|
||||
defaultScreen.toArray(linksArray);
|
||||
|
||||
if(defaultLinkHandlerScreenSelectedChoice == 0) {
|
||||
|
||||
defaultLinkHandlerScreenSelectedChoice = tinyDB.getInt("defaultScreenId");
|
||||
viewBinding.generalDeepLinkSelected.setText(getResources().getString(R.string.generalDeepLinkSelectedText));
|
||||
}
|
||||
|
||||
if(defaultLinkHandlerScreenSelectedChoice == 1) {
|
||||
|
||||
viewBinding.generalDeepLinkSelected.setText(getResources().getString(R.string.navRepos));
|
||||
}
|
||||
else if(defaultLinkHandlerScreenSelectedChoice == 2) {
|
||||
|
||||
viewBinding.generalDeepLinkSelected.setText(getResources().getString(R.string.navOrgs));
|
||||
}
|
||||
else if(defaultLinkHandlerScreenSelectedChoice == 3) {
|
||||
|
||||
viewBinding.generalDeepLinkSelected.setText(getResources().getString(R.string.pageTitleNotifications));
|
||||
}
|
||||
else if(defaultLinkHandlerScreenSelectedChoice == 4) {
|
||||
|
||||
viewBinding.generalDeepLinkSelected.setText(getResources().getString(R.string.navExplore));
|
||||
}
|
||||
|
||||
viewBinding.setDefaultLinkHandler.setOnClickListener(setDefaultLinkHandler -> {
|
||||
|
||||
AlertDialog.Builder dlBuilder = new AlertDialog.Builder(SettingsGeneralActivity.this);
|
||||
dlBuilder.setTitle(R.string.linkSelectorDialogTitle);
|
||||
|
||||
dlBuilder.setCancelable(defaultLinkHandlerScreenSelectedChoice != -1);
|
||||
|
||||
dlBuilder.setSingleChoiceItems(linksArray, defaultLinkHandlerScreenSelectedChoice, (dialogInterfaceHomeScreen, i) -> {
|
||||
|
||||
defaultLinkHandlerScreenSelectedChoice = i;
|
||||
viewBinding.generalDeepLinkSelected.setText(linksArray[i]);
|
||||
tinyDB.putInt("defaultScreenId", i);
|
||||
|
||||
dialogInterfaceHomeScreen.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
AlertDialog dlDialog = dlBuilder.create();
|
||||
dlDialog.show();
|
||||
});
|
||||
// link handler
|
||||
}
|
||||
|
||||
private void initCloseListener() { onClickListener = view -> finish(); }
|
||||
}
|
@ -0,0 +1,123 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.NumberPicker;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import com.pes.androidmaterialcolorpickerdialog.ColorPicker;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.databinding.ActivitySettingsNotificationsBinding;
|
||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.notifications.NotificationsMaster;
|
||||
|
||||
/**
|
||||
* Template Author M M Arif
|
||||
* Author opyale
|
||||
*/
|
||||
|
||||
public class SettingsNotificationsActivity extends BaseActivity {
|
||||
|
||||
private ActivitySettingsNotificationsBinding viewBinding;
|
||||
|
||||
@Override
|
||||
protected int getLayoutResourceId() {
|
||||
|
||||
return R.layout.activity_settings_notifications;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
viewBinding = ActivitySettingsNotificationsBinding.inflate(getLayoutInflater());
|
||||
View view = viewBinding.getRoot();
|
||||
setContentView(view);
|
||||
|
||||
View.OnClickListener onClickListener = viewClose -> finish();
|
||||
|
||||
viewBinding.close.setOnClickListener(onClickListener);
|
||||
|
||||
viewBinding.pollingDelaySelected.setText(String.format(getString(R.string.pollingDelaySelectedText), tinyDB.getInt("pollingDelayMinutes", StaticGlobalVariables.defaultPollingDelay)));
|
||||
viewBinding.chooseColorState.setCardBackgroundColor(tinyDB.getInt("notificationsLightColor", Color.GREEN));
|
||||
|
||||
viewBinding.enableNotificationsMode.setChecked(tinyDB.getBoolean("notificationsEnabled", true));
|
||||
viewBinding.enableLightsMode.setChecked(tinyDB.getBoolean("notificationsEnableLights", true));
|
||||
viewBinding.enableVibrationMode.setChecked(tinyDB.getBoolean("notificationsEnableVibration", true));
|
||||
|
||||
viewBinding.enableNotificationsMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
tinyDB.putBoolean("notificationsEnabled", isChecked);
|
||||
if(!isChecked) NotificationsMaster.fireWorker(ctx);
|
||||
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
// polling delay
|
||||
viewBinding.pollingDelayFrame.setOnClickListener(v -> {
|
||||
|
||||
NumberPicker numberPicker = new NumberPicker(ctx);
|
||||
numberPicker.setMinValue(StaticGlobalVariables.minimumPollingDelay);
|
||||
numberPicker.setMaxValue(StaticGlobalVariables.maximumPollingDelay);
|
||||
numberPicker.setValue(tinyDB.getInt("pollingDelayMinutes", StaticGlobalVariables.defaultPollingDelay));
|
||||
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);
|
||||
|
||||
viewBinding.pollingDelaySelected.setText(String.format(getString(R.string.pollingDelaySelectedText), numberPicker.getValue()));
|
||||
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
||||
builder.setView(numberPicker);
|
||||
builder.create().show();
|
||||
});
|
||||
|
||||
// lights switcher
|
||||
viewBinding.enableLightsMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
tinyDB.putBoolean("notificationsEnableLights", isChecked);
|
||||
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
// lights color chooser
|
||||
viewBinding.chooseColorFrame.setOnClickListener(v -> {
|
||||
|
||||
ColorPicker colorPicker = new ColorPicker(SettingsNotificationsActivity.this);
|
||||
colorPicker.setColor(tinyDB.getInt("notificationsLightColor", Color.GREEN));
|
||||
colorPicker.setCallback(color -> {
|
||||
|
||||
tinyDB.putInt("notificationsLightColor", color);
|
||||
viewBinding.chooseColorState.setCardBackgroundColor(color);
|
||||
colorPicker.dismiss();
|
||||
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
colorPicker.show();
|
||||
|
||||
});
|
||||
|
||||
// vibration switcher
|
||||
viewBinding.enableVibrationMode.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
tinyDB.putBoolean("notificationsEnableVibration", isChecked);
|
||||
Toasty.info(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,12 +1,10 @@
|
||||
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 com.google.android.material.switchmaterial.SwitchMaterial;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
|
||||
/**
|
||||
@ -15,7 +13,6 @@ import org.mian.gitnex.helpers.Toasty;
|
||||
|
||||
public class SettingsReportsActivity extends BaseActivity {
|
||||
|
||||
private Context appCtx;
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
@Override
|
||||
@ -28,38 +25,22 @@ public class SettingsReportsActivity extends BaseActivity {
|
||||
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 crashReportsSwitch = findViewById(R.id.crashReportsSwitch);
|
||||
SwitchMaterial crashReportsSwitch = findViewById(R.id.crashReportsSwitch);
|
||||
|
||||
if(tinyDb.getBoolean("crashReportingEnabled")) {
|
||||
crashReportsSwitch.setChecked(true);
|
||||
}
|
||||
else {
|
||||
crashReportsSwitch.setChecked(false);
|
||||
}
|
||||
crashReportsSwitch.setChecked(tinyDB.getBoolean("crashReportingEnabled"));
|
||||
|
||||
// crash reports switcher
|
||||
crashReportsSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
|
||||
if(isChecked) {
|
||||
tinyDb.putBoolean("crashReportingEnabled", true);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
}
|
||||
else {
|
||||
tinyDb.putBoolean("crashReportingEnabled", false);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
}
|
||||
|
||||
tinyDB.putBoolean("crashReportingEnabled", isChecked);
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
|
@ -7,16 +7,12 @@ 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.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.Version;
|
||||
import org.mian.gitnex.helpers.ssl.MemorizingTrustManager;
|
||||
import org.mian.gitnex.notifications.NotificationsMaster;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -26,21 +22,14 @@ import java.io.IOException;
|
||||
|
||||
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"};
|
||||
private static final String[] cacheSizeDataList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"};
|
||||
private static int cacheSizeDataSelectedChoice = 0;
|
||||
|
||||
private static String[] cacheSizeImagesList = {"50 MB", "100 MB", "250 MB", "500 MB", "1 GB"};
|
||||
private static final 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() {
|
||||
|
||||
@ -51,10 +40,6 @@ public class SettingsSecurityActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
String currentVersion = tinyDb.getString("giteaVersion");
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
|
||||
@ -64,36 +49,32 @@ 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);
|
||||
|
||||
if(!tinyDb.getString("cacheSizeStr").isEmpty()) {
|
||||
cacheSizeDataSelected.setText(tinyDb.getString("cacheSizeStr"));
|
||||
if(!tinyDB.getString("cacheSizeStr").isEmpty()) {
|
||||
|
||||
cacheSizeDataSelected.setText(tinyDB.getString("cacheSizeStr"));
|
||||
}
|
||||
|
||||
if(!tinyDb.getString("cacheSizeImagesStr").isEmpty()) {
|
||||
cacheSizeImagesSelected.setText(tinyDb.getString("cacheSizeImagesStr"));
|
||||
if(!tinyDB.getString("cacheSizeImagesStr").isEmpty()) {
|
||||
|
||||
cacheSizeImagesSelected.setText(tinyDB.getString("cacheSizeImagesStr"));
|
||||
}
|
||||
|
||||
if(cacheSizeDataSelectedChoice == 0) {
|
||||
cacheSizeDataSelectedChoice = tinyDb.getInt("cacheSizeId");
|
||||
|
||||
cacheSizeDataSelectedChoice = tinyDB.getInt("cacheSizeId");
|
||||
}
|
||||
|
||||
if(cacheSizeImagesSelectedChoice == 0) {
|
||||
cacheSizeImagesSelectedChoice = tinyDb.getInt("cacheSizeImagesId");
|
||||
}
|
||||
|
||||
if(new Version(currentVersion).less("1.12.3")) {
|
||||
pollingDelayFrame.setVisibility(View.GONE);
|
||||
cacheSizeImagesSelectedChoice = tinyDB.getInt("cacheSizeImagesId");
|
||||
}
|
||||
|
||||
pollingDelaySelected.setText(String.format(getString(R.string.pollingDelaySelectedText), tinyDb.getInt("pollingDelayMinutes", DEFAULT_POLLING_DELAY)));
|
||||
|
||||
// clear cache setter
|
||||
File cacheDir = appCtx.getCacheDir();
|
||||
clearCacheSelected.setText(FileUtils.byteCountToDisplaySize((int) FileUtils.sizeOfDirectory(cacheDir)));
|
||||
@ -113,14 +94,11 @@ public class SettingsSecurityActivity extends BaseActivity {
|
||||
FileUtils.mkdir(cacheDir.getAbsolutePath());
|
||||
this.recreate();
|
||||
this.overridePendingTransition(0, 0);
|
||||
|
||||
}
|
||||
catch (IOException e) {
|
||||
|
||||
Log.e("SettingsSecurity", e.toString());
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
||||
@ -134,28 +112,21 @@ public class SettingsSecurityActivity extends BaseActivity {
|
||||
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
||||
|
||||
tsBuilder.setTitle(getResources().getString(R.string.cacheSizeImagesDialogHeader));
|
||||
if(cacheSizeImagesSelectedChoice != -1) {
|
||||
tsBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
tsBuilder.setCancelable(false);
|
||||
}
|
||||
tsBuilder.setCancelable(cacheSizeImagesSelectedChoice != -1);
|
||||
|
||||
tsBuilder.setSingleChoiceItems(cacheSizeImagesList, cacheSizeImagesSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||
|
||||
cacheSizeImagesSelectedChoice = i;
|
||||
cacheSizeImagesSelected.setText(cacheSizeImagesList[i]);
|
||||
tinyDb.putString("cacheSizeImagesStr", cacheSizeImagesList[i]);
|
||||
tinyDb.putInt("cacheSizeImagesId", i);
|
||||
tinyDB.putString("cacheSizeImagesStr", cacheSizeImagesList[i]);
|
||||
tinyDB.putInt("cacheSizeImagesId", i);
|
||||
|
||||
dialogInterfaceTheme.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
AlertDialog cfDialog = tsBuilder.create();
|
||||
cfDialog.show();
|
||||
|
||||
});
|
||||
|
||||
// cache size data selection dialog
|
||||
@ -164,28 +135,21 @@ public class SettingsSecurityActivity extends BaseActivity {
|
||||
AlertDialog.Builder tsBuilder = new AlertDialog.Builder(SettingsSecurityActivity.this);
|
||||
|
||||
tsBuilder.setTitle(getResources().getString(R.string.cacheSizeDataDialogHeader));
|
||||
if(cacheSizeDataSelectedChoice != -1) {
|
||||
tsBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
tsBuilder.setCancelable(false);
|
||||
}
|
||||
tsBuilder.setCancelable(cacheSizeDataSelectedChoice != -1);
|
||||
|
||||
tsBuilder.setSingleChoiceItems(cacheSizeDataList, cacheSizeDataSelectedChoice, (dialogInterfaceTheme, i) -> {
|
||||
|
||||
cacheSizeDataSelectedChoice = i;
|
||||
cacheSizeDataSelected.setText(cacheSizeDataList[i]);
|
||||
tinyDb.putString("cacheSizeStr", cacheSizeDataList[i]);
|
||||
tinyDb.putInt("cacheSizeId", i);
|
||||
tinyDB.putString("cacheSizeStr", cacheSizeDataList[i]);
|
||||
tinyDB.putInt("cacheSizeId", i);
|
||||
|
||||
dialogInterfaceTheme.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
AlertDialog cfDialog = tsBuilder.create();
|
||||
cfDialog.show();
|
||||
|
||||
});
|
||||
|
||||
// certs deletion
|
||||
@ -199,53 +163,18 @@ public class SettingsSecurityActivity extends BaseActivity {
|
||||
|
||||
appCtx.getSharedPreferences(MemorizingTrustManager.KEYSTORE_NAME, Context.MODE_PRIVATE).edit().remove(MemorizingTrustManager.KEYSTORE_KEY).apply();
|
||||
|
||||
tinyDb.putBoolean("loggedInMode", false);
|
||||
tinyDb.remove("basicAuthPassword");
|
||||
tinyDb.putBoolean("basicAuthFlag", false);
|
||||
tinyDB.putBoolean("loggedInMode", false);
|
||||
tinyDB.remove("basicAuthPassword");
|
||||
tinyDB.putBoolean("basicAuthFlag", false);
|
||||
|
||||
Intent loginActivityIntent = new Intent().setClass(appCtx, LoginActivity.class);
|
||||
loginActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
appCtx.startActivity(loginActivityIntent);
|
||||
|
||||
});
|
||||
|
||||
builder.setNeutralButton(R.string.cancelButton, (dialog, which) -> dialog.dismiss());
|
||||
builder.create().show();
|
||||
|
||||
});
|
||||
|
||||
// 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() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.mian.gitnex.activities;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
@ -10,7 +9,6 @@ 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;
|
||||
|
||||
/**
|
||||
@ -19,7 +17,6 @@ import org.mian.gitnex.helpers.Toasty;
|
||||
|
||||
public class SettingsTranslationActivity extends BaseActivity {
|
||||
|
||||
private Context appCtx;
|
||||
private View.OnClickListener onClickListener;
|
||||
|
||||
private static String[] langList = {"English", "Arabic", "Chinese", "Czech", "Finnish", "French", "German", "Italian", "Latvian", "Persian",
|
||||
@ -36,9 +33,6 @@ public class SettingsTranslationActivity extends BaseActivity {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
appCtx = getApplicationContext();
|
||||
|
||||
TinyDB tinyDb = new TinyDB(appCtx);
|
||||
|
||||
ImageView closeActivity = findViewById(R.id.close);
|
||||
|
||||
@ -60,12 +54,14 @@ public class SettingsTranslationActivity extends BaseActivity {
|
||||
|
||||
});
|
||||
|
||||
if(!tinyDb.getString("localeStr").isEmpty()) {
|
||||
tvLanguageSelected.setText(tinyDb.getString("localeStr"));
|
||||
if(!tinyDB.getString("localeStr").isEmpty()) {
|
||||
|
||||
tvLanguageSelected.setText(tinyDB.getString("localeStr"));
|
||||
}
|
||||
|
||||
if(langSelectedChoice == 0) {
|
||||
langSelectedChoice = tinyDb.getInt("langId");
|
||||
|
||||
langSelectedChoice = tinyDB.getInt("langId");
|
||||
}
|
||||
|
||||
// language dialog
|
||||
@ -74,89 +70,98 @@ public class SettingsTranslationActivity extends BaseActivity {
|
||||
AlertDialog.Builder lBuilder = new AlertDialog.Builder(SettingsTranslationActivity.this);
|
||||
|
||||
lBuilder.setTitle(R.string.settingsLanguageSelectorDialogTitle);
|
||||
if(langSelectedChoice != -1) {
|
||||
lBuilder.setCancelable(true);
|
||||
}
|
||||
else {
|
||||
lBuilder.setCancelable(false);
|
||||
}
|
||||
lBuilder.setCancelable(langSelectedChoice != -1);
|
||||
|
||||
lBuilder.setSingleChoiceItems(langList, langSelectedChoice, (dialogInterface, i) -> {
|
||||
|
||||
langSelectedChoice = i;
|
||||
tvLanguageSelected.setText(langList[i]);
|
||||
tinyDb.putString("localeStr", langList[i]);
|
||||
tinyDb.putInt("langId", i);
|
||||
tinyDB.putString("localeStr", langList[i]);
|
||||
tinyDB.putInt("langId", i);
|
||||
|
||||
switch(langList[i]) {
|
||||
case "Arabic":
|
||||
tinyDb.putString("locale", "ar");
|
||||
|
||||
tinyDB.putString("locale", "ar");
|
||||
break;
|
||||
case "Chinese":
|
||||
tinyDb.putString("locale", "zh");
|
||||
|
||||
tinyDB.putString("locale", "zh");
|
||||
break;
|
||||
case "Czech":
|
||||
tinyDb.putString("locale", "cs");
|
||||
|
||||
tinyDB.putString("locale", "cs");
|
||||
break;
|
||||
case "Finnish":
|
||||
tinyDb.putString("locale", "fi");
|
||||
|
||||
tinyDB.putString("locale", "fi");
|
||||
break;
|
||||
case "French":
|
||||
tinyDb.putString("locale", "fr");
|
||||
|
||||
tinyDB.putString("locale", "fr");
|
||||
break;
|
||||
case "German":
|
||||
tinyDb.putString("locale", "de");
|
||||
|
||||
tinyDB.putString("locale", "de");
|
||||
break;
|
||||
case "Italian":
|
||||
tinyDb.putString("locale", "it");
|
||||
|
||||
tinyDB.putString("locale", "it");
|
||||
break;
|
||||
case "Latvian":
|
||||
tinyDb.putString("locale", "lv");
|
||||
|
||||
tinyDB.putString("locale", "lv");
|
||||
break;
|
||||
case "Persian":
|
||||
tinyDb.putString("locale", "fa");
|
||||
|
||||
tinyDB.putString("locale", "fa");
|
||||
break;
|
||||
case "Polish":
|
||||
tinyDb.putString("locale", "pl");
|
||||
|
||||
tinyDB.putString("locale", "pl");
|
||||
break;
|
||||
case "Portuguese/Brazilian":
|
||||
tinyDb.putString("locale", "pt");
|
||||
|
||||
tinyDB.putString("locale", "pt");
|
||||
break;
|
||||
case "Russian":
|
||||
tinyDb.putString("locale", "ru");
|
||||
|
||||
tinyDB.putString("locale", "ru");
|
||||
break;
|
||||
case "Serbian":
|
||||
tinyDb.putString("locale", "sr");
|
||||
|
||||
tinyDB.putString("locale", "sr");
|
||||
break;
|
||||
case "Spanish":
|
||||
tinyDb.putString("locale", "es");
|
||||
|
||||
tinyDB.putString("locale", "es");
|
||||
break;
|
||||
case "Turkish":
|
||||
tinyDb.putString("locale", "tr");
|
||||
|
||||
tinyDB.putString("locale", "tr");
|
||||
break;
|
||||
case "Ukrainian":
|
||||
tinyDb.putString("locale", "uk");
|
||||
|
||||
tinyDB.putString("locale", "uk");
|
||||
break;
|
||||
default:
|
||||
tinyDb.putString("locale", "en");
|
||||
|
||||
tinyDB.putString("locale", "en");
|
||||
break;
|
||||
}
|
||||
|
||||
tinyDb.putBoolean("refreshParent", true);
|
||||
tinyDB.putBoolean("refreshParent", true);
|
||||
this.recreate();
|
||||
this.overridePendingTransition(0, 0);
|
||||
dialogInterface.dismiss();
|
||||
Toasty.success(appCtx, getResources().getString(R.string.settingsSave));
|
||||
|
||||
});
|
||||
|
||||
lBuilder.setNeutralButton(getString(R.string.cancelButton), null);
|
||||
|
||||
AlertDialog lDialog = lBuilder.create();
|
||||
lDialog.show();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initCloseListener() {
|
||||
|
@ -50,12 +50,13 @@ public class AssigneesListAdapter extends RecyclerView.Adapter<AssigneesListAdap
|
||||
private ImageView assigneesAvatar;
|
||||
|
||||
private AssigneesViewHolder(View itemView) {
|
||||
|
||||
super(itemView);
|
||||
this.setIsRecyclable(false);
|
||||
|
||||
assigneesSelection = itemView.findViewById(R.id.assigneesSelection);
|
||||
assigneesName = itemView.findViewById(R.id.assigneesName);
|
||||
assigneesAvatar = itemView.findViewById(R.id.assigneesAvatar);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,9 +74,11 @@ public class AssigneesListAdapter extends RecyclerView.Adapter<AssigneesListAdap
|
||||
Collaborators currentItem = assigneesList.get(position);
|
||||
|
||||
if(currentItem.getFull_name().equals("")) {
|
||||
|
||||
holder.assigneesName.setText(currentItem.getLogin());
|
||||
}
|
||||
else {
|
||||
|
||||
holder.assigneesName.setText(currentItem.getFull_name());
|
||||
}
|
||||
PicassoService
|
||||
@ -90,6 +93,7 @@ public class AssigneesListAdapter extends RecyclerView.Adapter<AssigneesListAdap
|
||||
}
|
||||
|
||||
currentAssignees = new ArrayList<>(new LinkedHashSet<>(currentAssignees));
|
||||
|
||||
for(int i = 0; i < currentAssignees.size(); i++) {
|
||||
|
||||
if(currentAssignees.contains(currentItem.getLogin())) {
|
||||
@ -98,6 +102,7 @@ public class AssigneesListAdapter extends RecyclerView.Adapter<AssigneesListAdap
|
||||
assigneesStrings.add(currentAssignees.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
assigneesListener.assigneesInterface(assigneesStrings);
|
||||
|
||||
holder.assigneesSelection.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
@ -119,6 +124,7 @@ public class AssigneesListAdapter extends RecyclerView.Adapter<AssigneesListAdap
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
|
||||
return assigneesList.size();
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ public class CommitsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder
|
||||
@SuppressLint("SetTextI18n")
|
||||
void bindData(Commits commitsModel) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(ctx);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(ctx);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
|
||||
|
@ -2,6 +2,7 @@ package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
@ -14,9 +15,11 @@ import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.IssueDetailActivity;
|
||||
import org.mian.gitnex.database.api.DraftsApi;
|
||||
import org.mian.gitnex.database.models.DraftWithRepository;
|
||||
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
|
||||
import org.mian.gitnex.helpers.Markdown;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import java.util.List;
|
||||
@ -28,21 +31,16 @@ import java.util.List;
|
||||
public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsViewHolder> {
|
||||
|
||||
private List<DraftWithRepository> draftsList;
|
||||
private FragmentManager fragmentManager;
|
||||
private Context mCtx;
|
||||
private final FragmentManager fragmentManager;
|
||||
private final 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 DraftWithRepository draftWithRepository;
|
||||
|
||||
private final TextView draftText;
|
||||
private final TextView repoInfo;
|
||||
private final ImageView editCommentStatus;
|
||||
|
||||
private DraftsViewHolder(View itemView) {
|
||||
|
||||
@ -50,19 +48,12 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
||||
|
||||
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());
|
||||
int getDraftId = draftWithRepository.getDraftId();
|
||||
deleteDraft(getAdapterPosition());
|
||||
DraftsApi draftsApi = new DraftsApi(mCtx);
|
||||
draftsApi.deleteSingleDraft(getDraftId);
|
||||
@ -73,23 +64,26 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
|
||||
bundle.putString("commentBody", draftText.getText().toString());
|
||||
bundle.putString("issueNumber", issueNumber.getText().toString());
|
||||
bundle.putString("repositoryId", repoId.getText().toString());
|
||||
bundle.putString("commentBody", draftWithRepository.getDraftText());
|
||||
bundle.putString("issueNumber", String.valueOf(draftWithRepository.getIssueId()));
|
||||
bundle.putString("repositoryId", String.valueOf(draftWithRepository.getRepositoryId()));
|
||||
bundle.putString("draftTitle", repoInfo.getText().toString());
|
||||
bundle.putString("commentId", commentId.getText().toString());
|
||||
bundle.putString("draftId", draftId.getText().toString());
|
||||
bundle.putString("commentId", draftWithRepository.getCommentId());
|
||||
bundle.putString("draftId", String.valueOf(draftWithRepository.getDraftId()));
|
||||
|
||||
if(!commentId.getText().toString().isEmpty()) {
|
||||
if(!draftWithRepository.getCommentId().isEmpty()) {
|
||||
bundle.putString("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());
|
||||
TinyDB tinyDb = TinyDB.getInstance(mCtx);
|
||||
tinyDb.putString("issueNumber", String.valueOf(draftWithRepository.getIssueId()));
|
||||
tinyDb.putLong("repositoryId", draftWithRepository.getRepositoryId());
|
||||
tinyDb.putString("issueType", draftWithRepository.getIssueType());
|
||||
tinyDb.putString("repoFullName", draftWithRepository.getRepositoryOwner() + "/" + draftWithRepository.getRepositoryName());
|
||||
|
||||
BottomSheetReplyFragment.newInstance(bundle).show(fragmentManager, "replyBottomSheet");
|
||||
BottomSheetReplyFragment bottomSheetReplyFragment = BottomSheetReplyFragment.newInstance(bundle);
|
||||
bottomSheetReplyFragment.setOnInteractedListener(() -> mCtx.startActivity(new Intent(mCtx, IssueDetailActivity.class)));
|
||||
bottomSheetReplyFragment.show(fragmentManager, "replyBottomSheet");
|
||||
|
||||
});
|
||||
|
||||
@ -125,18 +119,13 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
||||
|
||||
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);
|
||||
holder.draftWithRepository = currentItem;
|
||||
|
||||
new Markdown(mCtx, currentItem.getDraftText(), holder.draftText);
|
||||
|
||||
if(!currentItem.getCommentId().equalsIgnoreCase("new")) {
|
||||
holder.editCommentStatus.setVisibility(View.VISIBLE);
|
||||
@ -144,7 +133,6 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
||||
else {
|
||||
holder.editCommentStatus.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -157,6 +145,4 @@ public class DraftsAdapter extends RecyclerView.Adapter<DraftsAdapter.DraftsView
|
||||
draftsList = list;
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
||||
tinyDb.putBoolean("resumeIssues", true);
|
||||
tinyDb.putBoolean("isRepoAdmin", isRepoAdmin.isChecked());
|
||||
@ -128,14 +128,13 @@ public class ExploreRepositoriesAdapter extends RecyclerView.Adapter<ExploreRepo
|
||||
//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 = RetrofitClient.getApiInterface(context).checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<WatchInfo>() {
|
||||
|
||||
|
@ -15,8 +15,9 @@ import android.widget.TextView;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
|
||||
import org.mian.gitnex.helpers.DiffTextView;
|
||||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.models.FileDiffView;
|
||||
import org.mian.gitnex.views.DiffTextView;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentSkipListMap;
|
||||
@ -36,9 +37,9 @@ public class FilesDiffAdapter extends BaseAdapter {
|
||||
private static int COLOR_SELECTED;
|
||||
private static int COLOR_FONT;
|
||||
|
||||
private Context context;
|
||||
private FragmentManager fragmentManager;
|
||||
private List<FileDiffView> fileDiffViews;
|
||||
private final Context context;
|
||||
private final FragmentManager fragmentManager;
|
||||
private final List<FileDiffView> fileDiffViews;
|
||||
|
||||
public FilesDiffAdapter(Context context, FragmentManager fragmentManager, List<FileDiffView> fileDiffViews) {
|
||||
|
||||
@ -48,11 +49,11 @@ public class FilesDiffAdapter extends BaseAdapter {
|
||||
|
||||
selectedViews = new ConcurrentSkipListMap<>();
|
||||
|
||||
COLOR_ADDED = getColorFromAttribute(R.attr.diffAddedColor);
|
||||
COLOR_REMOVED = getColorFromAttribute(R.attr.diffRemovedColor);
|
||||
COLOR_NORMAL = getColorFromAttribute(R.attr.primaryBackgroundColor);
|
||||
COLOR_SELECTED = getColorFromAttribute(R.attr.diffSelectedColor);
|
||||
COLOR_FONT = getColorFromAttribute(R.attr.inputTextColor);
|
||||
COLOR_ADDED = AppUtil.getColorFromAttribute(context, R.attr.diffAddedColor);
|
||||
COLOR_REMOVED = AppUtil.getColorFromAttribute(context, R.attr.diffRemovedColor);
|
||||
COLOR_NORMAL = AppUtil.getColorFromAttribute(context, R.attr.primaryBackgroundColor);
|
||||
COLOR_SELECTED = AppUtil.getColorFromAttribute(context, R.attr.diffSelectedColor);
|
||||
COLOR_FONT = AppUtil.getColorFromAttribute(context, R.attr.inputTextColor);
|
||||
|
||||
}
|
||||
|
||||
@ -185,7 +186,6 @@ public class FilesDiffAdapter extends BaseAdapter {
|
||||
|
||||
});
|
||||
|
||||
|
||||
diffTextView.setOnLongClickListener(v -> {
|
||||
|
||||
if(((DiffTextView) v).getCurrentBackgroundColor() == COLOR_SELECTED) {
|
||||
@ -257,13 +257,4 @@ public class FilesDiffAdapter extends BaseAdapter {
|
||||
|
||||
}
|
||||
|
||||
private int getColorFromAttribute(int resid) {
|
||||
|
||||
TypedValue typedValue = new TypedValue();
|
||||
context.getTheme().resolveAttribute(resid, typedValue, true);
|
||||
|
||||
return typedValue.data;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -5,14 +5,12 @@ import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.Spanned;
|
||||
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.fragment.app.FragmentManager;
|
||||
@ -25,33 +23,18 @@ import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.fragments.BottomSheetReplyFragment;
|
||||
import org.mian.gitnex.helpers.AlertDialogs;
|
||||
import org.mian.gitnex.helpers.ClickListener;
|
||||
import org.mian.gitnex.helpers.AppUtil;
|
||||
import org.mian.gitnex.helpers.Markdown;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.UserMentions;
|
||||
import org.mian.gitnex.models.IssueComments;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import org.mian.gitnex.views.ReactionList;
|
||||
import org.mian.gitnex.views.ReactionSpinner;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
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;
|
||||
|
||||
@ -61,94 +44,115 @@ import retrofit2.Callback;
|
||||
|
||||
public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdapter.IssueCommentViewHolder> {
|
||||
|
||||
private List<IssueComments> issuesComments;
|
||||
private FragmentManager fragmentManager;
|
||||
private Context mCtx;
|
||||
private final Context ctx;
|
||||
private final TinyDB tinyDB;
|
||||
private final Bundle bundle;
|
||||
private final List<IssueComments> issuesComments;
|
||||
private final FragmentManager fragmentManager;
|
||||
private final BottomSheetReplyFragment.OnInteractedListener onInteractedListener;
|
||||
|
||||
public IssueCommentsAdapter(Context mCtx, FragmentManager fragmentManager, List<IssueComments> issuesCommentsMain) {
|
||||
public IssueCommentsAdapter(Context ctx, Bundle bundle, List<IssueComments> issuesCommentsMain, FragmentManager fragmentManager, BottomSheetReplyFragment.OnInteractedListener onInteractedListener) {
|
||||
|
||||
this.mCtx = mCtx;
|
||||
this.fragmentManager = fragmentManager;
|
||||
this.ctx = ctx;
|
||||
this.bundle = bundle;
|
||||
this.issuesComments = issuesCommentsMain;
|
||||
this.fragmentManager = fragmentManager;
|
||||
this.onInteractedListener = onInteractedListener;
|
||||
|
||||
tinyDB = TinyDB.getInstance(ctx);
|
||||
|
||||
}
|
||||
|
||||
class IssueCommentViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private TextView issueNumber;
|
||||
private TextView commendId;
|
||||
private ImageView issueCommenterAvatar;
|
||||
private TextView issueComment;
|
||||
private TextView issueCommentDate;
|
||||
private TextView commendBodyRaw;
|
||||
private TextView commentModified;
|
||||
private TextView commenterUsername;
|
||||
private TextView htmlUrl;
|
||||
private IssueComments issueComment;
|
||||
|
||||
private IssueCommentViewHolder(View itemView) {
|
||||
private final ImageView avatar;
|
||||
private final TextView author;
|
||||
private final TextView information;
|
||||
private final TextView comment;
|
||||
private final LinearLayout commentReactionBadges;
|
||||
|
||||
super(itemView);
|
||||
private IssueCommentViewHolder(View view) {
|
||||
|
||||
issueNumber = itemView.findViewById(R.id.issueNumber);
|
||||
commendId = itemView.findViewById(R.id.commendId);
|
||||
issueCommenterAvatar = itemView.findViewById(R.id.issueCommenterAvatar);
|
||||
issueComment = itemView.findViewById(R.id.issueComment);
|
||||
issueCommentDate = itemView.findViewById(R.id.issueCommentDate);
|
||||
ImageView commentsOptionsMenu = itemView.findViewById(R.id.commentsOptionsMenu);
|
||||
commendBodyRaw = itemView.findViewById(R.id.commendBodyRaw);
|
||||
commentModified = itemView.findViewById(R.id.commentModified);
|
||||
commenterUsername = itemView.findViewById(R.id.commenterUsername);
|
||||
htmlUrl = itemView.findViewById(R.id.htmlUrl);
|
||||
super(view);
|
||||
|
||||
commentsOptionsMenu.setOnClickListener(v -> {
|
||||
avatar = view.findViewById(R.id.avatar);
|
||||
author = view.findViewById(R.id.author);
|
||||
information = view.findViewById(R.id.information);
|
||||
ImageView menu = view.findViewById(R.id.menu);
|
||||
comment = view.findViewById(R.id.comment);
|
||||
commentReactionBadges = view.findViewById(R.id.commentReactionBadges);
|
||||
|
||||
menu.setOnClickListener(v -> {
|
||||
|
||||
final Context ctx = v.getContext();
|
||||
final TinyDB tinyDb = new TinyDB(ctx);
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String loginUid = tinyDB.getString("loginUid");
|
||||
|
||||
@SuppressLint("InflateParams") View view = LayoutInflater.from(ctx).inflate(R.layout.bottom_sheet_issue_comments, null);
|
||||
@SuppressLint("InflateParams") View vw = LayoutInflater.from(ctx).inflate(R.layout.bottom_sheet_issue_comments, null);
|
||||
|
||||
TextView commentMenuEdit = view.findViewById(R.id.commentMenuEdit);
|
||||
TextView commentShare = view.findViewById(R.id.issueCommentShare);
|
||||
TextView commentMenuQuote = view.findViewById(R.id.commentMenuQuote);
|
||||
TextView commentMenuCopy = view.findViewById(R.id.commentMenuCopy);
|
||||
TextView commentMenuDelete = view.findViewById(R.id.commentMenuDelete);
|
||||
TextView issueCommentCopyUrl = view.findViewById(R.id.issueCommentCopyUrl);
|
||||
TextView commentMenuEdit = vw.findViewById(R.id.commentMenuEdit);
|
||||
TextView commentShare = vw.findViewById(R.id.issueCommentShare);
|
||||
TextView commentMenuQuote = vw.findViewById(R.id.commentMenuQuote);
|
||||
TextView commentMenuCopy = vw.findViewById(R.id.commentMenuCopy);
|
||||
TextView commentMenuDelete = vw.findViewById(R.id.commentMenuDelete);
|
||||
TextView issueCommentCopyUrl = vw.findViewById(R.id.issueCommentCopyUrl);
|
||||
|
||||
if(!loginUid.contentEquals(commenterUsername.getText())) {
|
||||
if(!loginUid.contentEquals(issueComment.getUser().getUsername())) {
|
||||
commentMenuEdit.setVisibility(View.GONE);
|
||||
commentMenuDelete.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(issueComment.getText().toString().isEmpty()) {
|
||||
if(issueComment.getBody().isEmpty()) {
|
||||
commentMenuCopy.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
BottomSheetDialog dialog = new BottomSheetDialog(ctx);
|
||||
dialog.setContentView(view);
|
||||
dialog.setContentView(vw);
|
||||
dialog.show();
|
||||
|
||||
commentMenuEdit.setOnClickListener(ediComment -> {
|
||||
LinearLayout linearLayout = vw.findViewById(R.id.commentReactionButtons);
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("commentId", commendId.getText().toString());
|
||||
bundle.putString("commentAction", "edit");
|
||||
bundle.putString("commentBody", commendBodyRaw.getText().toString());
|
||||
Bundle bundle1 = new Bundle();
|
||||
bundle1.putAll(bundle);
|
||||
bundle1.putInt("commentId", issueComment.getId());
|
||||
|
||||
BottomSheetReplyFragment.newInstance(bundle).show(fragmentManager, "replyBottomSheet");
|
||||
ReactionSpinner reactionSpinner = new ReactionSpinner(ctx, bundle1);
|
||||
reactionSpinner.setOnInteractedListener(() -> {
|
||||
|
||||
tinyDB.putBoolean("commentEdited", true);
|
||||
|
||||
onInteractedListener.onInteracted();
|
||||
dialog.dismiss();
|
||||
|
||||
});
|
||||
|
||||
commentShare.setOnClickListener(ediComment -> {
|
||||
linearLayout.addView(reactionSpinner);
|
||||
|
||||
commentMenuEdit.setOnClickListener(v1 -> {
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putInt("commentId", issueComment.getId());
|
||||
bundle.putString("commentAction", "edit");
|
||||
bundle.putString("commentBody", issueComment.getBody());
|
||||
|
||||
BottomSheetReplyFragment bottomSheetReplyFragment = BottomSheetReplyFragment.newInstance(bundle);
|
||||
bottomSheetReplyFragment.setOnInteractedListener(onInteractedListener);
|
||||
bottomSheetReplyFragment.show(fragmentManager, "replyBottomSheet");
|
||||
|
||||
dialog.dismiss();
|
||||
|
||||
});
|
||||
|
||||
commentShare.setOnClickListener(v1 -> {
|
||||
|
||||
// get comment Url
|
||||
CharSequence commentUrl = htmlUrl.getText();
|
||||
CharSequence commentUrl = issueComment.getHtml_url();
|
||||
|
||||
// share issue comment
|
||||
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
|
||||
sharingIntent.setType("text/plain");
|
||||
String intentHeader = tinyDb.getString("issueNumber") + ctx.getResources().getString(R.string.hash) + "issuecomment-" + commendId.getText() + " " + tinyDb.getString("issueTitle");
|
||||
String intentHeader = tinyDB.getString("issueNumber") + ctx.getResources().getString(R.string.hash) + "issuecomment-" + issueComment.getId() + " " + tinyDB.getString("issueTitle");
|
||||
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, intentHeader);
|
||||
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, commentUrl);
|
||||
ctx.startActivity(Intent.createChooser(sharingIntent, intentHeader));
|
||||
@ -157,10 +161,10 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
||||
|
||||
});
|
||||
|
||||
issueCommentCopyUrl.setOnClickListener(ediComment -> {
|
||||
issueCommentCopyUrl.setOnClickListener(v1 -> {
|
||||
|
||||
// comment Url
|
||||
CharSequence commentUrl = htmlUrl.getText();
|
||||
CharSequence commentUrl = issueComment.getHtml_url();
|
||||
|
||||
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
assert clipboard != null;
|
||||
@ -176,14 +180,14 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
||||
commentMenuQuote.setOnClickListener(v1 -> {
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
String commenterName = commenterUsername.getText().toString();
|
||||
String commenterName = issueComment.getUser().getUsername();
|
||||
|
||||
if(!commenterName.equals(tinyDb.getString("userLogin"))) {
|
||||
if(!commenterName.equals(tinyDB.getString("userLogin"))) {
|
||||
|
||||
stringBuilder.append("@").append(commenterName).append("\n\n");
|
||||
}
|
||||
|
||||
String[] lines = commendBodyRaw.getText().toString().split("\\R");
|
||||
String[] lines = issueComment.getBody().split("\\R");
|
||||
|
||||
for(String line : lines) {
|
||||
|
||||
@ -201,12 +205,12 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
||||
|
||||
});
|
||||
|
||||
commentMenuCopy.setOnClickListener(view1 -> {
|
||||
commentMenuCopy.setOnClickListener(v1 -> {
|
||||
|
||||
ClipboardManager clipboard = (ClipboardManager) Objects.requireNonNull(ctx).getSystemService(Context.CLIPBOARD_SERVICE);
|
||||
assert clipboard != null;
|
||||
|
||||
ClipData clip = ClipData.newPlainText("Comment on issue #" + issueNumber.getText().toString(), issueComment.getText().toString());
|
||||
ClipData clip = ClipData.newPlainText("Comment on issue #" + tinyDB.getString("issueNumber"), issueComment.getBody());
|
||||
clipboard.setPrimaryClip(clip);
|
||||
|
||||
dialog.dismiss();
|
||||
@ -214,9 +218,9 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
||||
|
||||
});
|
||||
|
||||
commentMenuDelete.setOnClickListener(deleteComment -> {
|
||||
commentMenuDelete.setOnClickListener(v1 -> {
|
||||
|
||||
deleteIssueComment(ctx, Integer.parseInt(commendId.getText().toString()), getAdapterPosition());
|
||||
deleteIssueComment(ctx, issueComment.getId(), getAdapterPosition());
|
||||
dialog.dismiss();
|
||||
|
||||
});
|
||||
@ -237,22 +241,19 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
||||
|
||||
private void deleteIssueComment(final Context ctx, final int commentId, int position) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(ctx);
|
||||
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").split("/");
|
||||
final String loginUid = tinyDB.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDB.getString(loginUid + "-token");
|
||||
String[] repoFullName = tinyDB.getString("repoFullName").split("/");
|
||||
|
||||
if (repoFullName.length != 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String repoOwner = repoFullName[0];
|
||||
final String repoName = repoFullName[1];
|
||||
|
||||
Call<JsonElement> call;
|
||||
|
||||
call = RetrofitClient
|
||||
.getInstance(instanceUrl, ctx)
|
||||
.getApiInterface()
|
||||
Call<JsonElement> call = RetrofitClient
|
||||
.getApiInterface(ctx)
|
||||
.deleteComment(instanceToken, repoOwner, repoName, commentId);
|
||||
|
||||
call.enqueue(new Callback<JsonElement>() {
|
||||
@ -260,47 +261,40 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<JsonElement> call, @NonNull retrofit2.Response<JsonElement> response) {
|
||||
|
||||
if(response.code() == 204) {
|
||||
switch(response.code()) {
|
||||
|
||||
updateAdapter(position);
|
||||
Toasty.success(ctx, ctx.getResources().getString(R.string.deleteCommentSuccess));
|
||||
case 204:
|
||||
updateAdapter(position);
|
||||
Toasty.success(ctx, ctx.getResources().getString(R.string.deleteCommentSuccess));
|
||||
break;
|
||||
|
||||
}
|
||||
else if(response.code() == 401) {
|
||||
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, ctx.getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||
case 401:
|
||||
AlertDialogs.authorizationTokenRevokedDialog(ctx, ctx.getResources().getString(R.string.alertDialogTokenRevokedTitle),
|
||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedMessage),
|
||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyNegativeButton),
|
||||
ctx.getResources().getString(R.string.alertDialogTokenRevokedCopyPositiveButton));
|
||||
break;
|
||||
|
||||
case 403:
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
break;
|
||||
|
||||
case 404:
|
||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||
break;
|
||||
|
||||
default:
|
||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||
|
||||
}
|
||||
else if(response.code() == 403) {
|
||||
|
||||
Toasty.error(ctx, ctx.getString(R.string.authorizeError));
|
||||
|
||||
}
|
||||
else if(response.code() == 404) {
|
||||
|
||||
Toasty.warning(ctx, ctx.getString(R.string.apiNotFound));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(ctx, ctx.getString(R.string.genericError));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NonNull Call<JsonElement> call, @NonNull Throwable t) {
|
||||
|
||||
Toasty.error(ctx, ctx.getResources().getString(R.string.genericServerResponseError));
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@ -311,109 +305,70 @@ public class IssueCommentsAdapter extends RecyclerView.Adapter<IssueCommentsAdap
|
||||
return new IssueCommentsAdapter.IssueCommentViewHolder(v);
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull IssueCommentsAdapter.IssueCommentViewHolder holder, int position) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
String timeFormat = tinyDB.getString("dateFormat");
|
||||
IssueComments issueComment = issuesComments.get(position);
|
||||
|
||||
IssueComments currentItem = issuesComments.get(position);
|
||||
holder.issueComment = issueComment;
|
||||
holder.author.setText(issueComment.getUser().getUsername());
|
||||
|
||||
holder.htmlUrl.setText(currentItem.getHtml_url());
|
||||
holder.commenterUsername.setText(currentItem.getUser().getUsername());
|
||||
holder.commendId.setText(String.valueOf(currentItem.getId()));
|
||||
holder.commendBodyRaw.setText(currentItem.getBody());
|
||||
PicassoService.getInstance(ctx).get()
|
||||
.load(issueComment.getUser().getAvatar_url())
|
||||
.placeholder(R.drawable.loader_animated)
|
||||
.transform(new RoundedTransformation(4, 0))
|
||||
.resize(AppUtil.getPixelsFromDensity(ctx, 35), AppUtil.getPixelsFromDensity(ctx, 35))
|
||||
.centerCrop()
|
||||
.into(holder.avatar);
|
||||
|
||||
if(!currentItem.getUser().getFull_name().equals("")) {
|
||||
holder.issueCommenterAvatar.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.issueCommenter) + currentItem.getUser().getFull_name(), mCtx));
|
||||
}
|
||||
else {
|
||||
holder.issueCommenterAvatar.setOnClickListener(new ClickListener(mCtx.getResources().getString(R.string.issueCommenter) + currentItem.getUser().getLogin(), mCtx));
|
||||
}
|
||||
new Markdown(ctx, EmojiParser.parseToUnicode(issueComment.getBody()), holder.comment);
|
||||
|
||||
PicassoService.getInstance(mCtx).get().load(currentItem.getUser().getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.issueCommenterAvatar);
|
||||
StringBuilder informationBuilder = null;
|
||||
if(issueComment.getCreated_at() != null) {
|
||||
|
||||
String cleanIssueComments = currentItem.getBody().trim();
|
||||
if(timeFormat.equals("pretty")) {
|
||||
|
||||
final Markwon markwon = Markwon.builder(Objects.requireNonNull(mCtx)).usePlugin(CorePlugin.create()).usePlugin(ImagesPlugin.create(new ImagesPlugin.ImagesConfigure() {
|
||||
|
||||
@Override
|
||||
public void configureImages(@NonNull ImagesPlugin plugin) {
|
||||
|
||||
plugin.addSchemeHandler(new SchemeHandler() {
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ImageItem handle(@NonNull String raw, @NonNull Uri uri) {
|
||||
|
||||
final int resourceId = mCtx.getResources().getIdentifier(raw.substring("drawable://".length()), "drawable", mCtx.getPackageName());
|
||||
|
||||
final Drawable drawable = mCtx.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(mCtx.getResources()));
|
||||
plugin.addMediaDecoder(SvgMediaDecoder.create());
|
||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(mCtx.getResources()));
|
||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create());
|
||||
informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreated_at(), Locale.getDefault(), "pretty", ctx));
|
||||
holder.information.setOnClickListener(v -> TimeHelper.customDateFormatForToastDateFormat(issueComment.getCreated_at()));
|
||||
|
||||
}
|
||||
})).usePlugin(new AbstractMarkwonPlugin() {
|
||||
else if(timeFormat.equals("normal")) {
|
||||
|
||||
@Override
|
||||
public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
|
||||
|
||||
builder.codeTextColor(tinyDb.getInt("codeBlockColor")).codeBackgroundColor(tinyDb.getInt("codeBlockBackground")).linkColor(mCtx.getResources().getColor(R.color.lightBlue));
|
||||
informationBuilder = new StringBuilder(TimeHelper.formatTime(issueComment.getCreated_at(), Locale.getDefault(), "normal", ctx));
|
||||
}
|
||||
|
||||
}).usePlugin(TablePlugin.create(mCtx)).usePlugin(TaskListPlugin.create(mCtx)).usePlugin(HtmlPlugin.create()).usePlugin(StrikethroughPlugin.create()).usePlugin(LinkifyPlugin.create()).build();
|
||||
if(!issueComment.getCreated_at().equals(issueComment.getUpdated_at())) {
|
||||
|
||||
Spanned bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(cleanIssueComments));
|
||||
markwon.setParsedMarkdown(holder.issueComment, UserMentions.UserMentionsFunc(mCtx, bodyWithMD, cleanIssueComments));
|
||||
|
||||
String edited;
|
||||
|
||||
if(!currentItem.getUpdated_at().equals(currentItem.getCreated_at())) {
|
||||
|
||||
edited = mCtx.getResources().getString(R.string.colorfulBulletSpan) + mCtx.getResources().getString(R.string.modifiedText);
|
||||
holder.commentModified.setVisibility(View.VISIBLE);
|
||||
holder.commentModified.setText(edited);
|
||||
holder.commentModified.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getUpdated_at()), mCtx));
|
||||
|
||||
}
|
||||
else {
|
||||
|
||||
holder.commentModified.setVisibility(View.INVISIBLE);
|
||||
if(informationBuilder != null) {
|
||||
|
||||
informationBuilder.append(ctx.getString(R.string.colorfulBulletSpan)).append(ctx.getString(R.string.modifiedText));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
holder.issueCommentDate.setText(TimeHelper.formatTime(currentItem.getCreated_at(), new Locale(locale), timeFormat, mCtx));
|
||||
holder.information.setText(informationBuilder);
|
||||
|
||||
Bundle bundle1 = new Bundle();
|
||||
bundle1.putAll(bundle);
|
||||
bundle1.putInt("commentId", issueComment.getId());
|
||||
|
||||
ReactionList reactionList = new ReactionList(ctx, bundle1);
|
||||
|
||||
holder.commentReactionBadges.addView(reactionList);
|
||||
reactionList.setOnReactionAddedListener(() -> {
|
||||
|
||||
if(holder.commentReactionBadges.getVisibility() != View.VISIBLE) {
|
||||
holder.commentReactionBadges.post(() -> holder.commentReactionBadges.setVisibility(View.VISIBLE));
|
||||
}
|
||||
});
|
||||
|
||||
if(timeFormat.equals("pretty")) {
|
||||
holder.issueCommentDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getCreated_at()), mCtx));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
|
||||
return issuesComments.size();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -123,7 +123,7 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
Intent intent = new Intent(context, IssueDetailActivity.class);
|
||||
intent.putExtra("issueNumber", issueNumber.getText());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
||||
tinyDb.putString("issueType", "Issue");
|
||||
context.startActivity(intent);
|
||||
@ -136,7 +136,7 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
Intent intent = new Intent(context, IssueDetailActivity.class);
|
||||
intent.putExtra("issueNumber", issueNumber.getText());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("issueNumber", issueNumber.getText().toString());
|
||||
tinyDb.putString("issueType", "Issue");
|
||||
context.startActivity(intent);
|
||||
@ -148,7 +148,7 @@ public class IssuesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
@SuppressLint("SetTextI18n")
|
||||
void bindData(Issues issuesModel) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
|
||||
|
@ -32,6 +32,8 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
||||
private List<Labels> labelsList;
|
||||
final private Context mCtx;
|
||||
private ArrayList<Integer> labelsArray = new ArrayList<>();
|
||||
private static String type;
|
||||
private static String orgName;
|
||||
|
||||
static class LabelsViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@ -77,6 +79,8 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
||||
intent.putExtra("labelTitle", labelTitle.getText());
|
||||
intent.putExtra("labelColor", labelColor.getText());
|
||||
intent.putExtra("labelAction", "edit");
|
||||
intent.putExtra("type", type);
|
||||
intent.putExtra("orgName", orgName);
|
||||
context.startActivity(intent);
|
||||
dialog.dismiss();
|
||||
|
||||
@ -87,8 +91,9 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
||||
AlertDialogs.labelDeleteDialog(context, labelTitle.getText().toString(), labelId.getText().toString(),
|
||||
context.getResources().getString(R.string.labelDeleteTitle),
|
||||
context.getResources().getString(R.string.labelDeleteMessage),
|
||||
context.getResources().getString(R.string.labelDeletePositiveButton),
|
||||
context.getResources().getString(R.string.labelDeleteNegativeButton));
|
||||
context.getResources().getString(R.string.labelDeleteTitle),
|
||||
context.getResources().getString(R.string.labelDeleteNegativeButton),
|
||||
type, orgName);
|
||||
dialog.dismiss();
|
||||
|
||||
});
|
||||
@ -98,9 +103,12 @@ public class LabelsAdapter extends RecyclerView.Adapter<LabelsAdapter.LabelsView
|
||||
}
|
||||
}
|
||||
|
||||
public LabelsAdapter(Context mCtx, List<Labels> labelsMain) {
|
||||
public LabelsAdapter(Context mCtx, List<Labels> labelsMain, String type, String orgName) {
|
||||
|
||||
this.mCtx = mCtx;
|
||||
this.labelsList = labelsMain;
|
||||
LabelsAdapter.type = type;
|
||||
LabelsAdapter.orgName = orgName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -48,12 +48,13 @@ public class LabelsListAdapter extends RecyclerView.Adapter<LabelsListAdapter.La
|
||||
private ImageView labelColor;
|
||||
|
||||
private LabelsViewHolder(View itemView) {
|
||||
|
||||
super(itemView);
|
||||
this.setIsRecyclable(false);
|
||||
|
||||
labelSelection = itemView.findViewById(R.id.labelSelection);
|
||||
labelText = itemView.findViewById(R.id.labelText);
|
||||
labelColor = itemView.findViewById(R.id.labelColor);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +86,7 @@ public class LabelsListAdapter extends RecyclerView.Adapter<LabelsListAdapter.La
|
||||
}
|
||||
|
||||
currentLabelsIds = new ArrayList<>(new LinkedHashSet<>(currentLabelsIds));
|
||||
|
||||
for(int i = 0; i < currentLabelsIds.size(); i++) {
|
||||
|
||||
if(currentLabelsIds.contains(currentItem.getId())) {
|
||||
@ -93,6 +95,7 @@ public class LabelsListAdapter extends RecyclerView.Adapter<LabelsListAdapter.La
|
||||
labelsIds.add(currentLabelsIds.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
labelsListener.labelsIdsInterface(labelsIds);
|
||||
|
||||
holder.labelSelection.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
@ -117,6 +120,7 @@ public class LabelsListAdapter extends RecyclerView.Adapter<LabelsListAdapter.La
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
|
||||
return labels.size();
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,6 @@ package org.mian.gitnex.adapters;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.text.Spanned;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -19,6 +16,7 @@ import com.vdurmont.emoji.EmojiParser;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.actions.MilestoneActions;
|
||||
import org.mian.gitnex.helpers.ClickListener;
|
||||
import org.mian.gitnex.helpers.Markdown;
|
||||
import org.mian.gitnex.helpers.StaticGlobalVariables;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
@ -26,27 +24,9 @@ import org.mian.gitnex.models.Milestones;
|
||||
import java.text.DateFormat;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -177,71 +157,18 @@ public class MilestonesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
@SuppressLint("SetTextI18n")
|
||||
void bindData(Milestones dataModel) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
|
||||
milestoneId.setText(String.valueOf(dataModel.getId()));
|
||||
milestoneStatus.setText(dataModel.getState());
|
||||
|
||||
Markwon markwon = Markwon.builder(Objects.requireNonNull(context)).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 = context.getResources().getIdentifier(
|
||||
raw.substring("drawable://".length()),
|
||||
"drawable",
|
||||
context.getPackageName());
|
||||
|
||||
final Drawable drawable = context.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(context.getResources()));
|
||||
plugin.addMediaDecoder(SvgMediaDecoder.create());
|
||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(context.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(context.getResources().getColor(R.color.lightBlue));
|
||||
}
|
||||
})
|
||||
.usePlugin(TablePlugin.create(context))
|
||||
.usePlugin(TaskListPlugin.create(context))
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.usePlugin(LinkifyPlugin.create())
|
||||
.build();
|
||||
|
||||
Spanned msTitle_ = markwon.toMarkdown(dataModel.getTitle());
|
||||
markwon.setParsedMarkdown(msTitle, msTitle_);
|
||||
new Markdown(context, dataModel.getTitle(), msTitle);
|
||||
|
||||
if(!dataModel.getDescription().equals("")) {
|
||||
|
||||
CharSequence bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(dataModel.getDescription()));
|
||||
msDescription.setText(bodyWithMD);
|
||||
|
||||
new Markdown(context, EmojiParser.parseToUnicode(dataModel.getDescription()), msDescription);
|
||||
}
|
||||
else {
|
||||
|
||||
|
@ -92,7 +92,7 @@ public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter.
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
||||
tinyDb.putString("repoType", repoType.getText().toString());
|
||||
//tinyDb.putBoolean("resumeIssues", true);
|
||||
@ -125,14 +125,13 @@ public class MyReposListAdapter extends RecyclerView.Adapter<MyReposListAdapter.
|
||||
//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 = RetrofitClient.getApiInterface(context).checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<WatchInfo>() {
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter<NotificationsAdap
|
||||
|
||||
public NotificationsAdapter(Context context, List<NotificationThread> notificationThreads, OnMoreClickedListener onMoreClickedListener, OnNotificationClickedListener onNotificationClickedListener) {
|
||||
|
||||
this.tinyDb = new TinyDB(context);
|
||||
this.tinyDb = TinyDB.getInstance(context);
|
||||
this.context = context;
|
||||
this.notificationThreads = notificationThreads;
|
||||
this.onMoreClickedListener = onMoreClickedListener;
|
||||
|
@ -45,27 +45,23 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
||||
image = itemView.findViewById(R.id.imageAvatar);
|
||||
organizationId = itemView.findViewById(R.id.organizationId);
|
||||
|
||||
itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
itemView.setOnClickListener(v -> {
|
||||
|
||||
Context context = v.getContext();
|
||||
Intent intent = new Intent(context, OrganizationDetailActivity.class);
|
||||
intent.putExtra("orgName", mTextView1.getText().toString());
|
||||
Context context = v.getContext();
|
||||
Intent intent = new Intent(context, OrganizationDetailActivity.class);
|
||||
intent.putExtra("orgName", mTextView1.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
tinyDb.putString("orgName", mTextView1.getText().toString());
|
||||
tinyDb.putString("organizationId", organizationId.getText().toString());
|
||||
tinyDb.putBoolean("organizationAction", true);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("orgName", mTextView1.getText().toString());
|
||||
tinyDb.putString("organizationId", organizationId.getText().toString());
|
||||
tinyDb.putBoolean("organizationAction", true);
|
||||
context.startActivity(intent);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public OrganizationsListAdapter(Context mCtx, List<UserOrganizations> orgsListMain) {
|
||||
|
||||
this.mCtx = mCtx;
|
||||
this.orgList = orgsListMain;
|
||||
orgListFull = new ArrayList<>(orgList);
|
||||
@ -74,6 +70,7 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
||||
@NonNull
|
||||
@Override
|
||||
public OrganizationsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_organizations, parent, false);
|
||||
return new OrganizationsViewHolder(v);
|
||||
}
|
||||
@ -88,11 +85,12 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
||||
|
||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar_url()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(120, 120).centerCrop().into(holder.image);
|
||||
holder.mTextView1.setText(currentItem.getUsername());
|
||||
|
||||
if (!currentItem.getDescription().equals("")) {
|
||||
|
||||
holder.mTextView2.setVisibility(View.VISIBLE);
|
||||
holder.mTextView2.setText(currentItem.getDescription());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -105,14 +103,19 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
||||
return orgFilter;
|
||||
}
|
||||
|
||||
private Filter orgFilter = new Filter() {
|
||||
private final Filter orgFilter = new Filter() {
|
||||
|
||||
@Override
|
||||
protected FilterResults performFiltering(CharSequence constraint) {
|
||||
|
||||
List<UserOrganizations> filteredList = new ArrayList<>();
|
||||
|
||||
if (constraint == null || constraint.length() == 0) {
|
||||
|
||||
filteredList.addAll(orgListFull);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
String filterPattern = constraint.toString().toLowerCase().trim();
|
||||
|
||||
for (UserOrganizations item : orgListFull) {
|
||||
@ -130,6 +133,7 @@ public class OrganizationsListAdapter extends RecyclerView.Adapter<Organizations
|
||||
|
||||
@Override
|
||||
protected void publishResults(CharSequence constraint, FilterResults results) {
|
||||
|
||||
orgList.clear();
|
||||
orgList.addAll((List) results.values);
|
||||
notifyDataSetChanged();
|
||||
|
@ -130,7 +130,7 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
intent.putExtra("prMergeable", prMergeable.getText());
|
||||
intent.putExtra("prHeadBranch", prHeadBranch.getText());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("issueNumber", prNumber.getText().toString());
|
||||
tinyDb.putString("prMergeable", prMergeable.getText().toString());
|
||||
tinyDb.putString("prHeadBranch", prHeadBranch.getText().toString());
|
||||
@ -149,7 +149,7 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
intent.putExtra("prMergeable", prMergeable.getText());
|
||||
intent.putExtra("prHeadBranch", prHeadBranch.getText());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("issueNumber", prNumber.getText().toString());
|
||||
tinyDb.putString("prMergeable", prMergeable.getText().toString());
|
||||
tinyDb.putString("prHeadBranch", prHeadBranch.getText().toString());
|
||||
@ -165,7 +165,7 @@ public class PullRequestsAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
|
||||
@SuppressLint("SetTextI18n")
|
||||
void bindData(PullRequests prModel) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(context);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
|
||||
|
@ -1,10 +1,7 @@
|
||||
package org.mian.gitnex.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -16,34 +13,16 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.vdurmont.emoji.EmojiParser;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.helpers.ClickListener;
|
||||
import org.mian.gitnex.helpers.Markdown;
|
||||
import org.mian.gitnex.helpers.RoundedTransformation;
|
||||
import org.mian.gitnex.helpers.TimeHelper;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.models.Releases;
|
||||
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;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -111,7 +90,7 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull ReleasesAdapter.ReleasesViewHolder holder, int position) {
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(mCtx);
|
||||
final String locale = tinyDb.getString("locale");
|
||||
final String timeFormat = tinyDb.getString("dateFormat");
|
||||
|
||||
@ -149,58 +128,8 @@ public class ReleasesAdapter extends RecyclerView.Adapter<ReleasesAdapter.Releas
|
||||
holder.releaseDate.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(currentItem.getPublished_at()), mCtx));
|
||||
}
|
||||
|
||||
final Markwon markwon = Markwon.builder(Objects.requireNonNull(mCtx))
|
||||
.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 = mCtx.getResources().getIdentifier(
|
||||
raw.substring("drawable://".length()),
|
||||
"drawable",
|
||||
mCtx.getPackageName());
|
||||
|
||||
final Drawable drawable = mCtx.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(mCtx.getResources()));
|
||||
plugin.addMediaDecoder(SvgMediaDecoder.create());
|
||||
plugin.defaultMediaDecoder(DefaultMediaDecoder.create(mCtx.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(mCtx.getResources().getColor(R.color.lightBlue));
|
||||
}
|
||||
})
|
||||
.usePlugin(TablePlugin.create(mCtx))
|
||||
.usePlugin(TaskListPlugin.create(mCtx))
|
||||
.usePlugin(HtmlPlugin.create())
|
||||
.usePlugin(StrikethroughPlugin.create())
|
||||
.usePlugin(LinkifyPlugin.create())
|
||||
.build();
|
||||
|
||||
Spanned bodyWithMD = markwon.toMarkdown(EmojiParser.parseToUnicode(currentItem.getBody()));
|
||||
|
||||
if(!currentItem.getBody().equals("")) {
|
||||
markwon.setParsedMarkdown(holder.releaseBodyContent, bodyWithMD);
|
||||
new Markdown(mCtx, currentItem.getBody(), holder.releaseBodyContent);
|
||||
}
|
||||
else {
|
||||
holder.releaseBodyContent.setText(R.string.noReleaseBodyContent);
|
||||
|
@ -211,7 +211,7 @@ public class RepoForksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
||||
tinyDb.putString("repoType", repoType_.getText().toString());
|
||||
//tinyDb.putBoolean("resumeIssues", true);
|
||||
@ -244,14 +244,13 @@ public class RepoForksAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
||||
//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 = RetrofitClient.getApiInterface(context).checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<WatchInfo>() {
|
||||
|
||||
|
@ -81,7 +81,7 @@ public class RepoStargazersAdapter extends BaseAdapter {
|
||||
UserInfo currentItem = stargazersList.get(position);
|
||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(180, 180).centerCrop().into(viewHolder.memberAvatar);
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(mCtx);
|
||||
Typeface myTypeface;
|
||||
|
||||
switch(tinyDb.getInt("customFontId", -1)) {
|
||||
|
@ -81,7 +81,7 @@ public class RepoWatchersAdapter extends BaseAdapter {
|
||||
UserInfo currentItem = watchersList.get(position);
|
||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(180, 180).centerCrop().into(viewHolder.memberAvatar);
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(mCtx);
|
||||
Typeface myTypeface;
|
||||
|
||||
switch(tinyDb.getInt("customFontId", -1)) {
|
||||
|
@ -23,9 +23,9 @@ 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.activities.RepoForksActivity;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||
@ -94,7 +94,7 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", repoFullName.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("repoFullName", repoFullName.getText().toString());
|
||||
tinyDb.putString("repoType", repoType_.getText().toString());
|
||||
//tinyDb.putBoolean("resumeIssues", true);
|
||||
@ -127,14 +127,13 @@ public class ReposListAdapter extends RecyclerView.Adapter<ReposListAdapter.Repo
|
||||
//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 = RetrofitClient.getApiInterface(context).checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<WatchInfo>() {
|
||||
|
||||
|
@ -23,9 +23,9 @@ 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.activities.RepoForksActivity;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||
@ -91,7 +91,7 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", fullName.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("repoFullName", fullName.getText().toString());
|
||||
tinyDb.putString("repoType", repoType.getText().toString());
|
||||
//tinyDb.putBoolean("resumeIssues", true);
|
||||
@ -124,12 +124,11 @@ public class RepositoriesByOrgAdapter extends RecyclerView.Adapter<RepositoriesB
|
||||
//store if user is watching this repo
|
||||
{
|
||||
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String token = "token " + tinyDb.getString(tinyDb.getString("loginUid") + "-token");
|
||||
|
||||
Call<WatchInfo> call;
|
||||
|
||||
call = RetrofitClient.getInstance(instanceUrl, context).getApiInterface().checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
call = RetrofitClient.getApiInterface(context).checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<WatchInfo>() {
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class SearchIssuesAdapter extends RecyclerView.Adapter<SearchIssuesAdapte
|
||||
|
||||
this.mCtx = mCtx;
|
||||
this.searchedList = dataList;
|
||||
this.tinyDb = new TinyDB(mCtx);
|
||||
this.tinyDb = TinyDB.getInstance(mCtx);
|
||||
}
|
||||
|
||||
class SearchViewHolder extends RecyclerView.ViewHolder {
|
||||
|
@ -23,9 +23,9 @@ 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.activities.RepoForksActivity;
|
||||
import org.mian.gitnex.clients.PicassoService;
|
||||
import org.mian.gitnex.clients.RetrofitClient;
|
||||
import org.mian.gitnex.database.api.RepositoriesApi;
|
||||
@ -91,7 +91,7 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
||||
Intent intent = new Intent(context, RepoDetailActivity.class);
|
||||
intent.putExtra("repoFullName", fullName.getText().toString());
|
||||
|
||||
TinyDB tinyDb = new TinyDB(context);
|
||||
TinyDB tinyDb = TinyDB.getInstance(context);
|
||||
tinyDb.putString("repoFullName", fullName.getText().toString());
|
||||
tinyDb.putString("repoType", repoType.getText().toString());
|
||||
//tinyDb.putBoolean("resumeIssues", true);
|
||||
@ -124,14 +124,13 @@ public class StarredReposListAdapter extends RecyclerView.Adapter<StarredReposLi
|
||||
//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 = RetrofitClient.getApiInterface(context).checkRepoWatchStatus(token, repoOwner, repoName);
|
||||
|
||||
call.enqueue(new Callback<WatchInfo>() {
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class TeamMembersByOrgAdapter extends BaseAdapter {
|
||||
UserInfo currentItem = teamMembersList.get(position);
|
||||
PicassoService.getInstance(mCtx).get().load(currentItem.getAvatar()).placeholder(R.drawable.loader_animated).transform(new RoundedTransformation(8, 0)).resize(180, 180).centerCrop().into(viewHolder.memberAvatar);
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final TinyDB tinyDb = TinyDB.getInstance(mCtx);
|
||||
Typeface myTypeface;
|
||||
|
||||
switch(tinyDb.getInt("customFontId", -1)) {
|
||||
|
@ -125,7 +125,7 @@ public class UserAccountsAdapter extends RecyclerView.Adapter<UserAccountsAdapte
|
||||
public void onBindViewHolder(@NonNull UserAccountsAdapter.UserAccountsViewHolder holder, int position) {
|
||||
|
||||
UserAccount currentItem = userAccountsList.get(position);
|
||||
tinyDB = new TinyDB(mCtx);
|
||||
tinyDB = TinyDB.getInstance(mCtx);
|
||||
|
||||
String url = UrlBuilder.fromString(currentItem.getInstanceUrl())
|
||||
.withPath("/")
|
||||
|
@ -31,7 +31,7 @@ public class UserAccountsListDialogAdapter extends ArrayAdapter<UserAccount> {
|
||||
|
||||
super(mCtx, resource, userAccounts);
|
||||
|
||||
tinyDB = new TinyDB(mCtx);
|
||||
tinyDB = TinyDB.getInstance(mCtx);
|
||||
this.userAccounts = userAccounts;
|
||||
this.mCtx = mCtx;
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class UserAccountsNavAdapter extends RecyclerView.Adapter<UserAccountsNav
|
||||
|
||||
private void customDialogUserAccountsList(List<UserAccount> allAccountsList) {
|
||||
|
||||
TinyDB tinyDB = new TinyDB(mCtx);
|
||||
TinyDB tinyDB = TinyDB.getInstance(mCtx);
|
||||
Dialog dialog = new Dialog(mCtx, R.style.ThemeOverlay_MaterialComponents_Dialog_Alert);
|
||||
dialog.setContentView(R.layout.custom_user_accounts_dialog);
|
||||
|
||||
|
@ -146,19 +146,16 @@ public class UserSearchAdapter extends RecyclerView.Adapter<UserSearchAdapter.Us
|
||||
|
||||
if(getItemCount() > 0) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
TinyDB tinyDb = TinyDB.getInstance(mCtx);
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
final String repoOwner = parts[0];
|
||||
final String repoName = parts[1];
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
Call<Collaborators> call = RetrofitClient
|
||||
.getInstance(instanceUrl, mCtx)
|
||||
.getApiInterface()
|
||||
.checkRepoCollaborator(Authorization.returnAuthentication(mCtx, loginUid, instanceToken), repoOwner, repoName, currentItem.getUsername());
|
||||
.getApiInterface(mCtx)
|
||||
.checkRepoCollaborator(Authorization.get(mCtx), repoOwner, repoName, currentItem.getUsername());
|
||||
|
||||
call.enqueue(new Callback<Collaborators>() {
|
||||
|
||||
|
@ -116,8 +116,7 @@ public class UserSearchForTeamMemberAdapter extends RecyclerView.Adapter<UserSea
|
||||
|
||||
if(getItemCount() > 0) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(mCtx);
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
TinyDB tinyDb = TinyDB.getInstance(mCtx);
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
String repoFullName = tinyDb.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
@ -125,9 +124,8 @@ public class UserSearchForTeamMemberAdapter extends RecyclerView.Adapter<UserSea
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
Call<UserInfo> call = RetrofitClient
|
||||
.getInstance(instanceUrl, mCtx)
|
||||
.getApiInterface()
|
||||
.checkTeamMember(Authorization.returnAuthentication(mCtx, loginUid, instanceToken), teamId, currentItem.getLogin());
|
||||
.getApiInterface(mCtx)
|
||||
.checkTeamMember(Authorization.get(mCtx), teamId, currentItem.getLogin());
|
||||
|
||||
call.enqueue(new Callback<UserInfo>() {
|
||||
|
||||
|
@ -1,79 +0,0 @@
|
||||
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 java.io.File;
|
||||
import java.security.SecureRandom;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import okhttp3.Cache;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class AppApiService {
|
||||
|
||||
public static <S> S createService(Class<S> serviceClass, String instanceURL, Context ctx) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(ctx);
|
||||
final boolean connToInternet = AppUtil.hasNetworkConnection(ctx);
|
||||
File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
|
||||
int cacheSize = FilesData.returnOnlyNumber(tinyDb.getString("cacheSizeStr")) * 1024 * 1024;
|
||||
Cache cache = new Cache(httpCacheDirectory, cacheSize);
|
||||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
try {
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
|
||||
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
|
||||
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
|
||||
|
||||
OkHttpClient okHttpClient = new OkHttpClient.Builder()
|
||||
.cache(cache)
|
||||
//.addInterceptor(logging)
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
|
||||
.hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()))
|
||||
.addInterceptor(chain -> {
|
||||
|
||||
Request request = chain.request();
|
||||
if(connToInternet) {
|
||||
request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
|
||||
}
|
||||
else {
|
||||
request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
|
||||
}
|
||||
return chain.proceed(request);
|
||||
|
||||
}).build();
|
||||
|
||||
Retrofit.Builder builder = new Retrofit.Builder()
|
||||
.baseUrl(instanceURL)
|
||||
.client(okHttpClient)
|
||||
.addConverterFactory(GsonConverterFactory.create());
|
||||
|
||||
Retrofit retrofit = builder.build();
|
||||
return retrofit.create(serviceClass);
|
||||
|
||||
}
|
||||
catch(Exception e) {
|
||||
Log.e("onFailure", e.toString());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -20,7 +20,7 @@ import okhttp3.OkHttpClient;
|
||||
public class PicassoService {
|
||||
|
||||
private static PicassoService picassoService;
|
||||
private static File cachePath;
|
||||
private final File cachePath;
|
||||
private Picasso picasso;
|
||||
|
||||
private PicassoService(Context context) {
|
||||
@ -54,7 +54,6 @@ public class PicassoService {
|
||||
|
||||
Log.e("PicassoService", e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public Picasso get() {
|
||||
|
@ -10,6 +10,8 @@ import org.mian.gitnex.interfaces.ApiInterface;
|
||||
import org.mian.gitnex.interfaces.WebInterface;
|
||||
import java.io.File;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
@ -27,15 +29,15 @@ import retrofit2.converter.scalars.ScalarsConverterFactory;
|
||||
|
||||
public class RetrofitClient {
|
||||
|
||||
private Retrofit retrofit;
|
||||
private static final Map<String, ApiInterface> apiInterfaces = new ConcurrentHashMap<>();
|
||||
private static final Map<String, WebInterface> webInterfaces = new ConcurrentHashMap<>();
|
||||
|
||||
private RetrofitClient(String instanceUrl, Context ctx) {
|
||||
private static Retrofit createRetrofit(Context context, String instanceUrl) {
|
||||
|
||||
TinyDB tinyDb = new TinyDB(ctx);
|
||||
final boolean connToInternet = AppUtil.hasNetworkConnection(ctx);
|
||||
int cacheSize = FilesData.returnOnlyNumber(tinyDb.getString("cacheSizeStr")) * 1024 * 1024;
|
||||
File httpCacheDirectory = new File(ctx.getCacheDir(), "responses");
|
||||
Cache cache = new Cache(httpCacheDirectory, cacheSize);
|
||||
TinyDB tinyDB = TinyDB.getInstance(context);
|
||||
|
||||
int cacheSize = FilesData.returnOnlyNumber(tinyDB.getString("cacheSizeStr")) * 1024 * 1024;
|
||||
Cache cache = new Cache(new File(context.getCacheDir(), "responses"), cacheSize);
|
||||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
@ -44,47 +46,80 @@ public class RetrofitClient {
|
||||
|
||||
SSLContext sslContext = SSLContext.getInstance("TLS");
|
||||
|
||||
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(ctx);
|
||||
sslContext.init(null, new X509TrustManager[]{memorizingTrustManager}, new SecureRandom());
|
||||
MemorizingTrustManager memorizingTrustManager = new MemorizingTrustManager(context);
|
||||
sslContext.init(null, new X509TrustManager[]{ memorizingTrustManager }, new SecureRandom());
|
||||
|
||||
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder().cache(cache)
|
||||
//.addInterceptor(logging)
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager).hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier())).addInterceptor(chain -> {
|
||||
//.addInterceptor(logging)
|
||||
.sslSocketFactory(sslContext.getSocketFactory(), memorizingTrustManager)
|
||||
.hostnameVerifier(memorizingTrustManager.wrapHostnameVerifier(HttpsURLConnection.getDefaultHostnameVerifier()))
|
||||
.addInterceptor(chain -> {
|
||||
|
||||
Request request = chain.request();
|
||||
if(connToInternet) {
|
||||
request = request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build();
|
||||
}
|
||||
else {
|
||||
request = request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
|
||||
}
|
||||
return chain.proceed(request);
|
||||
});
|
||||
Request request = chain.request();
|
||||
|
||||
Retrofit.Builder builder = new Retrofit.Builder().baseUrl(instanceUrl).client(okHttpClient.build()).addConverterFactory(ScalarsConverterFactory.create()).addConverterFactory(GsonConverterFactory.create());
|
||||
request = AppUtil.hasNetworkConnection(context) ?
|
||||
request.newBuilder().header("Cache-Control", "public, max-age=" + 60).build() :
|
||||
request.newBuilder().header("Cache-Control", "public, only-if-cached, max-stale=" + 60 * 60 * 24 * 30).build();
|
||||
|
||||
retrofit = builder.build();
|
||||
return chain.proceed(request);
|
||||
|
||||
});
|
||||
|
||||
return new Retrofit.Builder()
|
||||
.baseUrl(instanceUrl)
|
||||
.client(okHttpClient.build())
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
}
|
||||
catch(Exception e) {
|
||||
Log.e("onFailure", e.toString());
|
||||
|
||||
Log.e("onFailureRetrofit", e.toString());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static synchronized RetrofitClient getInstance(String instanceUrl, Context ctx) {
|
||||
public static ApiInterface getApiInterface(Context context) {
|
||||
|
||||
return new RetrofitClient(instanceUrl, ctx);
|
||||
return getApiInterface(context, TinyDB.getInstance(context).getString("instanceUrl"));
|
||||
}
|
||||
|
||||
public ApiInterface getApiInterface() {
|
||||
public static WebInterface getWebInterface(Context context) {
|
||||
|
||||
String instanceUrl = TinyDB.getInstance(context).getString("instanceUrl");
|
||||
instanceUrl = instanceUrl.substring(0, instanceUrl.lastIndexOf("api/v1/"));
|
||||
|
||||
return getWebInterface(context, instanceUrl);
|
||||
|
||||
return retrofit.create(ApiInterface.class);
|
||||
}
|
||||
|
||||
public WebInterface getWebInterface() {
|
||||
public static ApiInterface getApiInterface(Context context, String url) {
|
||||
if(!apiInterfaces.containsKey(url)) {
|
||||
|
||||
return retrofit.create(WebInterface.class);
|
||||
ApiInterface apiInterface = createRetrofit(context, url)
|
||||
.create(ApiInterface.class);
|
||||
|
||||
apiInterfaces.put(url, apiInterface);
|
||||
return apiInterface;
|
||||
|
||||
}
|
||||
|
||||
return apiInterfaces.get(url);
|
||||
}
|
||||
|
||||
public static WebInterface getWebInterface(Context context, String url) {
|
||||
if(!webInterfaces.containsKey(url)) {
|
||||
|
||||
WebInterface webInterface = createRetrofit(context, url)
|
||||
.create(WebInterface.class);
|
||||
|
||||
webInterfaces.put(url, webInterface);
|
||||
return webInterface;
|
||||
|
||||
}
|
||||
|
||||
return webInterfaces.get(url);
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ public class DraftsApi {
|
||||
draftsDao = db.draftsDao();
|
||||
}
|
||||
|
||||
public long insertDraft(int repositoryId, int draftAccountId, int issueId, String draftText, String draftType, String commentId) {
|
||||
public long insertDraft(int repositoryId, int draftAccountId, int issueId, String draftText, String draftType, String commentId, String issueType) {
|
||||
|
||||
Draft draft = new Draft();
|
||||
draft.setDraftRepositoryId(repositoryId);
|
||||
@ -35,7 +35,8 @@ public class DraftsApi {
|
||||
draft.setIssueId(issueId);
|
||||
draft.setDraftText(draftText);
|
||||
draft.setDraftType(draftType);
|
||||
draft.setCommentId(draftType);
|
||||
draft.setCommentId(commentId);
|
||||
draft.setIssueType(issueType);
|
||||
|
||||
return insertDraftAsyncTask(draft);
|
||||
}
|
||||
@ -50,7 +51,7 @@ public class DraftsApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.draftsRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.draftsApi, e.toString());
|
||||
}
|
||||
|
||||
return draftId;
|
||||
@ -66,7 +67,7 @@ public class DraftsApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.draftsRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.draftsApi, e.toString());
|
||||
}
|
||||
|
||||
return draftId;
|
||||
@ -82,7 +83,7 @@ public class DraftsApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.draftsRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.draftsApi, e.toString());
|
||||
}
|
||||
|
||||
return checkDraftFlag;
|
||||
|
@ -47,7 +47,7 @@ public class RepositoriesApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.repositoriesApi, e.toString());
|
||||
}
|
||||
|
||||
return repositoryId;
|
||||
@ -63,7 +63,7 @@ public class RepositoriesApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.repositoriesApi, e.toString());
|
||||
}
|
||||
|
||||
return repository;
|
||||
@ -89,7 +89,7 @@ public class RepositoriesApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.repositoriesApi, e.toString());
|
||||
}
|
||||
|
||||
return checkRepository;
|
||||
@ -105,7 +105,7 @@ public class RepositoriesApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.repositoriesApi, e.toString());
|
||||
}
|
||||
|
||||
return repository;
|
||||
@ -121,7 +121,7 @@ public class RepositoriesApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.repositoriesRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.repositoriesApi, e.toString());
|
||||
}
|
||||
|
||||
return repository;
|
||||
|
@ -17,6 +17,7 @@ public class UserAccountsApi {
|
||||
|
||||
private static UserAccountsDao userAccountsDao;
|
||||
private static UserAccount userAccount;
|
||||
private static List<UserAccount> userAccounts;
|
||||
private static Integer checkAccount;
|
||||
private static long accountId;
|
||||
|
||||
@ -49,7 +50,7 @@ public class UserAccountsApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.userAccountsRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.userAccountsApi, e.toString());
|
||||
}
|
||||
|
||||
return accountId;
|
||||
@ -80,7 +81,7 @@ public class UserAccountsApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.userAccountsRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.userAccountsApi, e.toString());
|
||||
}
|
||||
|
||||
return userAccount;
|
||||
@ -96,7 +97,7 @@ public class UserAccountsApi {
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.userAccountsRepository, e.toString());
|
||||
Log.e(StaticGlobalVariables.userAccountsApi, e.toString());
|
||||
}
|
||||
|
||||
return checkAccount;
|
||||
@ -107,6 +108,22 @@ public class UserAccountsApi {
|
||||
return userAccountsDao.fetchAllAccounts();
|
||||
}
|
||||
|
||||
public List<UserAccount> usersAccounts() {
|
||||
|
||||
try {
|
||||
|
||||
Thread thread = new Thread(() -> userAccounts = userAccountsDao.userAccounts());
|
||||
thread.start();
|
||||
thread.join();
|
||||
}
|
||||
catch(InterruptedException e) {
|
||||
|
||||
Log.e(StaticGlobalVariables.userAccountsApi, e.toString());
|
||||
}
|
||||
|
||||
return userAccounts;
|
||||
}
|
||||
|
||||
public void deleteAccount(final int accountId) {
|
||||
|
||||
new Thread(() -> userAccountsDao.deleteAccount(accountId)).start();
|
||||
|
@ -20,6 +20,9 @@ public interface UserAccountsDao {
|
||||
@Query("SELECT * FROM UserAccounts ORDER BY accountId ASC")
|
||||
LiveData<List<UserAccount>> fetchAllAccounts();
|
||||
|
||||
@Query("SELECT * FROM UserAccounts ORDER BY accountId ASC")
|
||||
List<UserAccount> userAccounts();
|
||||
|
||||
@Query("SELECT COUNT(accountId) FROM UserAccounts WHERE accountName = :accountName")
|
||||
Integer getCount(String accountName);
|
||||
|
||||
|
@ -19,7 +19,7 @@ import org.mian.gitnex.database.models.UserAccount;
|
||||
*/
|
||||
|
||||
@Database(entities = {Draft.class, Repository.class, UserAccount.class},
|
||||
version = 2, exportSchema = false)
|
||||
version = 3, exportSchema = false)
|
||||
public abstract class GitnexDatabase extends RoomDatabase {
|
||||
|
||||
private static GitnexDatabase gitnexDatabase;
|
||||
@ -27,10 +27,11 @@ public abstract class GitnexDatabase extends RoomDatabase {
|
||||
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)
|
||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3)
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -49,7 +50,14 @@ public abstract class GitnexDatabase extends RoomDatabase {
|
||||
|
||||
//database.execSQL("DROP TABLE Drafts");
|
||||
database.execSQL("ALTER TABLE 'Drafts' ADD COLUMN 'commentId' TEXT");
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private static final Migration MIGRATION_2_3 = new Migration(2, 3) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
|
||||
database.execSQL("ALTER TABLE 'Drafts' ADD COLUMN 'issueType' TEXT");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -26,6 +26,8 @@ public class Draft implements Serializable {
|
||||
private String draftType;
|
||||
@Nullable
|
||||
private String commentId;
|
||||
@Nullable
|
||||
private String issueType;
|
||||
|
||||
public int getDraftId() {
|
||||
|
||||
@ -99,4 +101,15 @@ public class Draft implements Serializable {
|
||||
this.commentId = commentId;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getIssueType() {
|
||||
|
||||
return issueType;
|
||||
}
|
||||
|
||||
public void setIssueType(@Nullable String issueType) {
|
||||
|
||||
this.issueType = issueType;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ public class DraftWithRepository {
|
||||
private String draftText;
|
||||
private String draftType;
|
||||
private String commentId;
|
||||
private String issueType;
|
||||
|
||||
public int getRepositoryId() {
|
||||
|
||||
@ -130,4 +131,14 @@ public class DraftWithRepository {
|
||||
this.commentId = commentId;
|
||||
}
|
||||
|
||||
public String getIssueType() {
|
||||
|
||||
return issueType;
|
||||
}
|
||||
|
||||
public void setIssueType(String issueType) {
|
||||
|
||||
this.issueType = issueType;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public class AboutFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
|
||||
FragmentAboutBinding viewBinding = FragmentAboutBinding.inflate(inflater, container, false);
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
TinyDB tinyDb = TinyDB.getInstance(getContext());
|
||||
|
||||
viewBinding.appVersion.setText(AppUtil.getAppVersion(requireContext()));
|
||||
viewBinding.userServerVersion.setText(tinyDb.getString("giteaVersion"));
|
||||
@ -32,15 +32,6 @@ public class AboutFragment extends Fragment {
|
||||
|
||||
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.pageTitleAbout));
|
||||
|
||||
viewBinding.donationLinkLiberapay.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);
|
||||
});
|
||||
|
||||
viewBinding.donationLinkPatreon.setOnClickListener(v12 -> {
|
||||
|
||||
Intent intent = new Intent();
|
||||
@ -72,7 +63,6 @@ public class AboutFragment extends Fragment {
|
||||
|
||||
viewBinding.supportHeader.setVisibility(View.GONE);
|
||||
viewBinding.dividerSupport.setVisibility(View.GONE);
|
||||
viewBinding.donationLinkLiberapay.setVisibility(View.GONE);
|
||||
viewBinding.donationLinkPatreon.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,6 @@ import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.AdminGetUsersActivity;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
@ -23,8 +22,6 @@ public class AdministrationFragment extends Fragment {
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_administration, container, false);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
|
||||
TextView adminUsers = v.findViewById(R.id.adminUsers);
|
||||
|
||||
adminUsers.setOnClickListener(v1 -> startActivity(new Intent(getContext(), AdminGetUsersActivity.class)));
|
||||
|
@ -24,7 +24,7 @@ public class BottomSheetNotificationsFilterFragment extends BottomSheetDialogFra
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
|
||||
this.tinyDB = new TinyDB(context);
|
||||
this.tinyDB = TinyDB.getInstance(context);
|
||||
super.onAttach(context);
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ public class BottomSheetOrganizationFragment extends BottomSheetDialogFragment {
|
||||
TextView createTeam = v.findViewById(R.id.createTeam);
|
||||
TextView createRepository = v.findViewById(R.id.createRepository);
|
||||
TextView copyOrgUrl = v.findViewById(R.id.copyOrgUrl);
|
||||
TextView createLabel = v.findViewById(R.id.createLabel);
|
||||
|
||||
createTeam.setOnClickListener(v1 -> {
|
||||
|
||||
@ -35,6 +36,12 @@ public class BottomSheetOrganizationFragment extends BottomSheetDialogFragment {
|
||||
dismiss();
|
||||
});
|
||||
|
||||
createLabel.setOnClickListener(v1 -> {
|
||||
|
||||
bmListener.onButtonClicked("label");
|
||||
dismiss();
|
||||
});
|
||||
|
||||
createRepository.setOnClickListener(v12 -> {
|
||||
|
||||
bmListener.onButtonClicked("repository");
|
||||
|
@ -1,12 +1,14 @@
|
||||
package org.mian.gitnex.fragments;
|
||||
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
@ -14,6 +16,8 @@ import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.actions.ActionResult;
|
||||
@ -31,6 +35,9 @@ import java.util.Objects;
|
||||
|
||||
public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
|
||||
private enum Mode { EDIT, SEND }
|
||||
private Mode mode = Mode.SEND;
|
||||
|
||||
private TinyDB tinyDB;
|
||||
private DraftsApi draftsApi;
|
||||
|
||||
@ -39,12 +46,13 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
private int issueNumber;
|
||||
private long draftId;
|
||||
|
||||
private OnInteractedListener onInteractedListener;
|
||||
private TextView draftsHint;
|
||||
|
||||
@Override
|
||||
public void onAttach(@NonNull Context context) {
|
||||
|
||||
tinyDB = new TinyDB(context);
|
||||
tinyDB = TinyDB.getInstance(context);
|
||||
draftsApi = new DraftsApi(context);
|
||||
|
||||
repositoryId = (int) tinyDB.getLong("repositoryId", 0);
|
||||
@ -54,6 +62,7 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
super.onAttach(context);
|
||||
}
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@ -63,7 +72,7 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
|
||||
draftsHint = view.findViewById(R.id.drafts_hint);
|
||||
|
||||
EditText commentContent = view.findViewById(R.id.comment);
|
||||
EditText comment = view.findViewById(R.id.comment);
|
||||
TextView toolbarTitle = view.findViewById(R.id.toolbar_title);
|
||||
ImageButton close = view.findViewById(R.id.close);
|
||||
ImageButton drafts = view.findViewById(R.id.drafts);
|
||||
@ -71,9 +80,12 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
|
||||
send.setEnabled(false);
|
||||
|
||||
if(Objects.equals(arguments.getString("commentAction"), "edit")) {
|
||||
if(Objects.equals(arguments.getString("commentAction"), "edit") &&
|
||||
arguments.getString("draftId") == null) {
|
||||
|
||||
send.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_save));
|
||||
mode = Mode.EDIT;
|
||||
|
||||
send.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(arguments.getString("draftId") != null) {
|
||||
@ -95,21 +107,40 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
send.setEnabled(true);
|
||||
send.setAlpha(1f);
|
||||
|
||||
commentContent.setText(arguments.getString("commentBody"));
|
||||
comment.setText(arguments.getString("commentBody"));
|
||||
|
||||
if(arguments.getBoolean("cursorToEnd", false)) {
|
||||
|
||||
commentContent.setSelection(commentContent.length());
|
||||
comment.setSelection(comment.length());
|
||||
}
|
||||
}
|
||||
|
||||
commentContent.requestFocus();
|
||||
commentContent.addTextChangedListener(new TextWatcher() {
|
||||
comment.requestFocus();
|
||||
comment.setOnTouchListener((v, event) -> {
|
||||
|
||||
BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from((View) view.getParent());
|
||||
|
||||
switch(event.getAction()) {
|
||||
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_SCROLL:
|
||||
bottomSheetBehavior.setDraggable(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
bottomSheetBehavior.setDraggable(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
comment.addTextChangedListener(new TextWatcher() {
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
||||
String text = commentContent.getText().toString();
|
||||
String text = comment.getText().toString();
|
||||
|
||||
if(text.isEmpty()) {
|
||||
|
||||
@ -127,6 +158,7 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
|
||||
@Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
@Override public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
|
||||
});
|
||||
|
||||
close.setOnClickListener(v -> dismiss());
|
||||
@ -138,33 +170,69 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
startActivity(intent);
|
||||
|
||||
dismiss();
|
||||
|
||||
});
|
||||
|
||||
send.setOnClickListener(v -> IssueActions
|
||||
.reply(getContext(), commentContent.getText().toString(), issueNumber)
|
||||
.accept((status, result) -> {
|
||||
send.setOnClickListener(v -> {
|
||||
|
||||
if(status == ActionResult.Status.SUCCESS) {
|
||||
if(mode == Mode.SEND) {
|
||||
|
||||
Toasty.success(getContext(), getString(R.string.commentSuccess));
|
||||
IssueActions
|
||||
.reply(getContext(), comment.getText().toString(), issueNumber)
|
||||
.accept((status, result) -> {
|
||||
|
||||
tinyDB.putBoolean("commentPosted", true);
|
||||
tinyDB.putBoolean("resumeIssues", true);
|
||||
tinyDB.putBoolean("resumePullRequests", true);
|
||||
if(status == ActionResult.Status.SUCCESS) {
|
||||
|
||||
if(draftId != 0 && tinyDB.getBoolean("draftsCommentsDeletionEnabled")) {
|
||||
Toasty.success(getContext(), getString(R.string.commentSuccess));
|
||||
|
||||
draftsApi.deleteSingleDraft((int) draftId);
|
||||
}
|
||||
if(draftId != 0 && tinyDB.getBoolean("draftsCommentsDeletionEnabled")) {
|
||||
draftsApi.deleteSingleDraft((int) draftId);
|
||||
}
|
||||
|
||||
dismiss();
|
||||
}
|
||||
else {
|
||||
tinyDB.putBoolean("commentPosted", true);
|
||||
tinyDB.putBoolean("resumeIssues", true);
|
||||
tinyDB.putBoolean("resumePullRequests", true);
|
||||
|
||||
Toasty.error(getContext(), getString(R.string.commentError));
|
||||
dismiss();
|
||||
}
|
||||
}));
|
||||
if(onInteractedListener != null) {
|
||||
onInteractedListener.onInteracted();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(getContext(), getString(R.string.commentError));
|
||||
}
|
||||
|
||||
dismiss();
|
||||
|
||||
});
|
||||
} else {
|
||||
|
||||
IssueActions
|
||||
.edit(getContext(), comment.getText().toString(), arguments.getInt("commentId"))
|
||||
.accept((status, result) -> {
|
||||
|
||||
if(status == ActionResult.Status.SUCCESS) {
|
||||
|
||||
if(draftId != 0 && tinyDB.getBoolean("draftsCommentsDeletionEnabled")) {
|
||||
draftsApi.deleteSingleDraft((int) draftId);
|
||||
}
|
||||
|
||||
tinyDB.putBoolean("commentEdited", true);
|
||||
|
||||
if(onInteractedListener != null) {
|
||||
onInteractedListener.onInteracted();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
Toasty.error(getContext(), getString(R.string.genericError));
|
||||
}
|
||||
|
||||
dismiss();
|
||||
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
@ -193,9 +261,26 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
}
|
||||
else {
|
||||
|
||||
String draftType;
|
||||
if(tinyDB.getString("issueType").equalsIgnoreCase("Issue")) {
|
||||
|
||||
draftType = StaticGlobalVariables.draftTypeIssue;
|
||||
}
|
||||
else if(tinyDB.getString("issueType").equalsIgnoreCase("Pull")) {
|
||||
|
||||
draftType = StaticGlobalVariables.draftTypePull;
|
||||
}
|
||||
else {
|
||||
|
||||
draftType = "";
|
||||
}
|
||||
|
||||
if(draftId == 0) {
|
||||
draftId = draftsApi.insertDraft(repositoryId, currentActiveAccountId, issueNumber, text, StaticGlobalVariables.draftTypeComment, "TODO");
|
||||
} else {
|
||||
|
||||
draftId = draftsApi.insertDraft(repositoryId, currentActiveAccountId, issueNumber, text, draftType, "TODO", tinyDB.getString("issueType"));
|
||||
}
|
||||
else {
|
||||
|
||||
DraftsApi.updateDraft(text, (int) draftId, "TODO");
|
||||
}
|
||||
|
||||
@ -211,4 +296,12 @@ public class BottomSheetReplyFragment extends BottomSheetDialogFragment {
|
||||
|
||||
return fragment;
|
||||
}
|
||||
|
||||
public void setOnInteractedListener(OnInteractedListener onInteractedListener) {
|
||||
|
||||
this.onInteractedListener = onInteractedListener;
|
||||
}
|
||||
|
||||
public interface OnInteractedListener { void onInteracted(); }
|
||||
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ public class BottomSheetRepoFragment extends BottomSheetDialogFragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
View v = inflater.inflate(R.layout.bottom_sheet_repo, container, false);
|
||||
|
||||
final TinyDB tinyDb = new TinyDB(getContext());
|
||||
final TinyDB tinyDb = TinyDB.getInstance(getContext());
|
||||
|
||||
TextView createLabel = v.findViewById(R.id.createLabel);
|
||||
TextView createIssue = v.findViewById(R.id.createNewIssue);
|
||||
|
@ -8,6 +8,7 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -20,6 +21,7 @@ import org.mian.gitnex.activities.MergePullRequestActivity;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.helpers.Toasty;
|
||||
import org.mian.gitnex.helpers.Version;
|
||||
import org.mian.gitnex.views.ReactionSpinner;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -37,7 +39,7 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
||||
View v = inflater.inflate(R.layout.bottom_sheet_single_issue, container, false);
|
||||
|
||||
final Context ctx = getContext();
|
||||
final TinyDB tinyDB = new TinyDB(ctx);
|
||||
final TinyDB tinyDB = TinyDB.getInstance(ctx);
|
||||
|
||||
TextView editIssue = v.findViewById(R.id.editIssue);
|
||||
TextView editLabels = v.findViewById(R.id.editLabels);
|
||||
@ -51,6 +53,29 @@ public class BottomSheetSingleIssueFragment extends BottomSheetDialogFragment {
|
||||
TextView subscribeIssue = v.findViewById(R.id.subscribeIssue);
|
||||
TextView unsubscribeIssue = v.findViewById(R.id.unsubscribeIssue);
|
||||
|
||||
LinearLayout linearLayout = v.findViewById(R.id.commentReactionButtons);
|
||||
|
||||
Bundle bundle1 = new Bundle();
|
||||
|
||||
String repoFullName = tinyDB.getString("repoFullName");
|
||||
String[] parts = repoFullName.split("/");
|
||||
|
||||
bundle1.putString("repoOwner", parts[0]);
|
||||
bundle1.putString("repoName", parts[1]);
|
||||
bundle1.putInt("issueId", Integer.parseInt(tinyDB.getString("issueNumber")));
|
||||
|
||||
ReactionSpinner reactionSpinner = new ReactionSpinner(ctx, bundle1);
|
||||
reactionSpinner.setOnInteractedListener(() -> {
|
||||
|
||||
tinyDB.putBoolean("singleIssueUpdate", true);
|
||||
|
||||
bmListener.onButtonClicked("onResume");
|
||||
dismiss();
|
||||
|
||||
});
|
||||
|
||||
linearLayout.addView(reactionSpinner);
|
||||
|
||||
if(tinyDB.getString("issueType").equalsIgnoreCase("Pull")) {
|
||||
|
||||
editIssue.setText(R.string.editPrText);
|
||||
|
@ -16,7 +16,6 @@ import androidx.lifecycle.ViewModelProvider;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.adapters.CollaboratorsAdapter;
|
||||
import org.mian.gitnex.helpers.Authorization;
|
||||
import org.mian.gitnex.helpers.TinyDB;
|
||||
import org.mian.gitnex.models.Collaborators;
|
||||
import org.mian.gitnex.viewmodels.CollaboratorsViewModel;
|
||||
import java.util.List;
|
||||
@ -65,18 +64,12 @@ public class CollaboratorsFragment extends Fragment {
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_collaborators, container, false);
|
||||
TinyDB tinyDb = new TinyDB(getContext());
|
||||
final String instanceUrl = tinyDb.getString("instanceUrl");
|
||||
final String loginUid = tinyDb.getString("loginUid");
|
||||
final String instanceToken = "token " + tinyDb.getString(loginUid + "-token");
|
||||
|
||||
noDataCollaborators = v.findViewById(R.id.noDataCollaborators);
|
||||
|
||||
mProgressBar = v.findViewById(R.id.progress_bar);
|
||||
|
||||
mGridView = v.findViewById(R.id.gridView);
|
||||
|
||||
fetchDataAsync(instanceUrl, Authorization.returnAuthentication(getContext(), loginUid, instanceToken), repoOwner, repoName);
|
||||
|
||||
fetchDataAsync(Authorization.get(getContext()), repoOwner, repoName);
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -96,11 +89,11 @@ public class CollaboratorsFragment extends Fragment {
|
||||
void onFragmentInteraction(Uri uri);
|
||||
}
|
||||
|
||||
private void fetchDataAsync(String instanceUrl, String instanceToken, String owner, String repo) {
|
||||
private void fetchDataAsync(String instanceToken, String owner, String repo) {
|
||||
|
||||
CollaboratorsViewModel collaboratorsModel = new ViewModelProvider(this).get(CollaboratorsViewModel.class);
|
||||
|
||||
collaboratorsModel.getCollaboratorsList(instanceUrl, instanceToken, owner, repo, getContext()).observe(getViewLifecycleOwner(), new Observer<List<Collaborators>>() {
|
||||
collaboratorsModel.getCollaboratorsList(instanceToken, owner, repo, getContext()).observe(getViewLifecycleOwner(), new Observer<List<Collaborators>>() {
|
||||
@Override
|
||||
public void onChanged(@Nullable List<Collaborators> collaboratorsListMain) {
|
||||
adapter = new CollaboratorsAdapter(getContext(), collaboratorsListMain);
|
||||
|
@ -20,6 +20,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import org.mian.gitnex.R;
|
||||
import org.mian.gitnex.activities.MainActivity;
|
||||
import org.mian.gitnex.adapters.DraftsAdapter;
|
||||
import org.mian.gitnex.database.api.DraftsApi;
|
||||
import org.mian.gitnex.database.models.DraftWithRepository;
|
||||
@ -51,7 +52,9 @@ public class DraftsFragment extends Fragment {
|
||||
ctx = getContext();
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
TinyDB tinyDb = new TinyDB(ctx);
|
||||
((MainActivity) requireActivity()).setActionBarTitle(getResources().getString(R.string.titleDrafts));
|
||||
|
||||
TinyDB tinyDb = TinyDB.getInstance(ctx);
|
||||
|
||||
draftsList_ = new ArrayList<>();
|
||||
draftsApi = new DraftsApi(ctx);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user