Merge branch '37-fix-crash-within-tabs' of mmarif/GitNex into master

This commit is contained in:
M M Arif 2019-09-14 09:43:54 +00:00 committed by Gitea
commit e8e0cf904b
9 changed files with 100 additions and 99 deletions

View File

@ -172,7 +172,7 @@ public class RepoDetailActivity extends AppCompatActivity implements RepoBottomS
public class SectionsPagerAdapter extends FragmentStatePagerAdapter { public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
SectionsPagerAdapter(FragmentManager fm) { SectionsPagerAdapter(FragmentManager fm) {
super(fm); super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
} }
@NonNull @NonNull

View File

@ -66,7 +66,7 @@ public class BranchesAdapter extends RecyclerView.Adapter<BranchesAdapter.Branch
holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getUsername())); holder.branchCommitAuthor.setText(mCtx.getResources().getString(R.string.commitAuthor, currentItem.getCommit().getAuthor().getUsername()));
} }
holder.branchCommitHash.setText(mCtx.getResources().getString(R.string.commitHash, UrlHelper.cleanUrl(instanceUrl), currentItem.getCommit().getUrl())); holder.branchCommitHash.setText(mCtx.getResources().getString(R.string.commitHash, "", currentItem.getCommit().getUrl()));
} }

View File

@ -1,7 +1,6 @@
package org.mian.gitnex.fragments; package org.mian.gitnex.fragments;
import android.content.Context; import android.content.Context;
import android.graphics.Color;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -15,7 +14,6 @@ import ru.noties.markwon.core.CorePlugin;
import ru.noties.markwon.core.MarkwonTheme; import ru.noties.markwon.core.MarkwonTheme;
import ru.noties.markwon.ext.strikethrough.StrikethroughPlugin; import ru.noties.markwon.ext.strikethrough.StrikethroughPlugin;
import ru.noties.markwon.ext.tables.TablePlugin; import ru.noties.markwon.ext.tables.TablePlugin;
import ru.noties.markwon.ext.tables.TableTheme;
import ru.noties.markwon.ext.tasklist.TaskListPlugin; import ru.noties.markwon.ext.tasklist.TaskListPlugin;
import ru.noties.markwon.html.HtmlPlugin; import ru.noties.markwon.html.HtmlPlugin;
import ru.noties.markwon.image.ImagesPlugin; import ru.noties.markwon.image.ImagesPlugin;
@ -220,53 +218,57 @@ public class RepoInfoFragment extends Fragment {
UserRepositories repoInfo = response.body(); UserRepositories repoInfo = response.body();
if (response.isSuccessful()) { if (isAdded()) {
if (response.code() == 200) { if (response.isSuccessful()) {
assert repoInfo != null; if (response.code() == 200) {
repoNameInfo.setText(repoInfo.getName());
repoOwnerInfo.setText(owner);
repoDescriptionInfo.setText(repoInfo.getDescription());
repoWebsiteInfo.setText(repoInfo.getWebsite());
repoSizeInfo.setText(AppUtil.formatFileSize(repoInfo.getSize()));
repoDefaultBranchInfo.setText(repoInfo.getDefault_branch());
repoSshUrlInfo.setText(repoInfo.getSsh_url());
repoCloneUrlInfo.setText(repoInfo.getClone_url());
repoRepoUrlInfo.setText(repoInfo.getHtml_url());
repoForksCountInfo.setText(repoInfo.getForks_count());
switch (timeFormat) { assert repoInfo != null;
case "pretty": { repoNameInfo.setText(repoInfo.getName());
PrettyTime prettyTime = new PrettyTime(new Locale(locale)); repoOwnerInfo.setText(owner);
String createdTime = prettyTime.format(repoInfo.getCreated_at()); repoDescriptionInfo.setText(repoInfo.getDescription());
repoCreatedAtInfo.setText(createdTime); repoWebsiteInfo.setText(repoInfo.getWebsite());
repoCreatedAtInfo.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(repoInfo.getCreated_at()), getContext())); repoSizeInfo.setText(AppUtil.formatFileSize(repoInfo.getSize()));
break; repoDefaultBranchInfo.setText(repoInfo.getDefault_branch());
} repoSshUrlInfo.setText(repoInfo.getSsh_url());
case "normal": { repoCloneUrlInfo.setText(repoInfo.getClone_url());
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale)); repoRepoUrlInfo.setText(repoInfo.getHtml_url());
String createdTime = formatter.format(repoInfo.getCreated_at()); repoForksCountInfo.setText(repoInfo.getForks_count());
repoCreatedAtInfo.setText(createdTime);
break; switch (timeFormat) {
} case "pretty": {
case "normal1": { PrettyTime prettyTime = new PrettyTime(new Locale(locale));
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale)); String createdTime = prettyTime.format(repoInfo.getCreated_at());
String createdTime = formatter.format(repoInfo.getCreated_at()); repoCreatedAtInfo.setText(createdTime);
repoCreatedAtInfo.setText(createdTime); repoCreatedAtInfo.setOnClickListener(new ClickListener(TimeHelper.customDateFormatForToastDateFormat(repoInfo.getCreated_at()), getContext()));
break; break;
}
case "normal": {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd '" + getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
String createdTime = formatter.format(repoInfo.getCreated_at());
repoCreatedAtInfo.setText(createdTime);
break;
}
case "normal1": {
DateFormat formatter = new SimpleDateFormat("dd-MM-yyyy '" + getResources().getString(R.string.timeAtText) + "' HH:mm", new Locale(locale));
String createdTime = formatter.format(repoInfo.getCreated_at());
repoCreatedAtInfo.setText(createdTime);
break;
}
} }
mProgressBar.setVisibility(View.GONE);
pageContent.setVisibility(View.VISIBLE);
} }
mProgressBar.setVisibility(View.GONE); }
pageContent.setVisibility(View.VISIBLE); else {
Log.e("onFailure", String.valueOf(response.code()));
} }
} }
else {
Log.e("onFailure", String.valueOf(response.code()));
}
} }
@ -292,58 +294,58 @@ public class RepoInfoFragment extends Fragment {
@Override @Override
public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) { public void onResponse(@NonNull Call<String> call, @NonNull retrofit2.Response<String> response) {
if (response.code() == 200) { if (isAdded()) {
final Markwon markwon = Markwon.builder(Objects.requireNonNull(getContext())) if (response.code() == 200) {
.usePlugin(CorePlugin.create())
.usePlugin(OkHttpImagesPlugin.create(new OkHttpClient())) final Markwon markwon = Markwon.builder(Objects.requireNonNull(getContext()))
.usePlugin(ImagesPlugin.createWithAssets(getContext())) .usePlugin(CorePlugin.create())
.usePlugin(new AbstractMarkwonPlugin() { .usePlugin(OkHttpImagesPlugin.create(new OkHttpClient()))
@Override .usePlugin(ImagesPlugin.createWithAssets(getContext()))
public void configureTheme(@NonNull MarkwonTheme.Builder builder) { .usePlugin(new AbstractMarkwonPlugin() {
builder @Override
.codeTextColor(tinyDb.getInt("codeBlockColor")) public void configureTheme(@NonNull MarkwonTheme.Builder builder) {
.codeBackgroundColor(tinyDb.getInt("codeBlockBackground")) builder
.linkColor(getResources().getColor(R.color.lightBlue)); .codeTextColor(tinyDb.getInt("codeBlockColor"))
} .codeBackgroundColor(tinyDb.getInt("codeBlockBackground"))
}) .linkColor(getResources().getColor(R.color.lightBlue));
.usePlugin(TablePlugin.create(getContext())) }
.usePlugin(TaskListPlugin.create(getContext())) })
.usePlugin(HtmlPlugin.create()) .usePlugin(TablePlugin.create(getContext()))
.usePlugin(GifPlugin.create()) .usePlugin(TaskListPlugin.create(getContext()))
.usePlugin(StrikethroughPlugin.create()) .usePlugin(HtmlPlugin.create())
.build(); .usePlugin(GifPlugin.create())
.usePlugin(StrikethroughPlugin.create())
.build();
CharSequence bodyWithMD = null;
if (response.body() != null) {
bodyWithMD = markwon.toMarkdown(response.body());
}
repoFileContents.setText(bodyWithMD);
} 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.info(ctx, ctx.getString(R.string.authorizeError));
} else if (response.code() == 404) {
fileContentsFrameHeader.setVisibility(View.GONE);
fileContentsFrame.setVisibility(View.GONE);
} else {
Toasty.info(getContext(), getString(R.string.genericError));
CharSequence bodyWithMD = null;
if (response.body() != null) {
bodyWithMD = markwon.toMarkdown(response.body());
} }
repoFileContents.setText(bodyWithMD);
}
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.info(ctx, ctx.getString(R.string.authorizeError));
}
else if(response.code() == 404) {
fileContentsFrameHeader.setVisibility(View.GONE);
fileContentsFrame.setVisibility(View.GONE);
}
else {
Toasty.info(getContext(), getString(R.string.genericError));
} }
} }

View File

@ -9,11 +9,9 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:paddingStart="15dp" android:paddingBottom="5dp"
android:paddingEnd="15dp"
android:paddingTop="10dp"
android:paddingBottom="15dp"
android:id="@+id/branchesFrame" android:id="@+id/branchesFrame"
android:layout_margin="15dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView

View File

@ -107,6 +107,7 @@
android:textIsSelectable="true" android:textIsSelectable="true"
android:textSize="16sp" android:textSize="16sp"
android:paddingTop="5dp" android:paddingTop="5dp"
android:autoLink="web"
android:textColor="@color/colorWhite"/> android:textColor="@color/colorWhite"/>
<TextView <TextView

View File

@ -9,7 +9,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="15dp" android:layout_margin="15dp"
android:id="@+id/labelsFrame" android:id="@+id/labelsFrame"
android:orientation="horizontal"> android:orientation="horizontal">

View File

@ -9,7 +9,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="15dp" android:layout_margin="15dp"
android:id="@+id/milestoneFrame" android:id="@+id/milestoneFrame"
android:orientation="vertical"> android:orientation="vertical">

View File

@ -11,7 +11,7 @@
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:fitsSystemWindows="true" android:fitsSystemWindows="true"
android:orientation="vertical" android:orientation="vertical"
android:padding="15dp" android:layout_margin="15dp"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<LinearLayout <LinearLayout

View File

@ -11,7 +11,7 @@
android:id="@+id/relativeLayoutFrame" android:id="@+id/relativeLayoutFrame"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="15dp" android:layout_margin="15dp"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
tools:context=".activities.RepoDetailActivity"> tools:context=".activities.RepoDetailActivity">