diff --git a/app/build.gradle b/app/build.gradle index 250794d5..a2193ec4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,5 +1,6 @@ plugins { id 'com.android.application' + id 'org.jetbrains.kotlin.android' } android { @@ -34,6 +35,11 @@ android { versionNameSuffix ' (DEBUG)' } } + + sourceSets { + main.java.srcDirs += 'src/main/kotlin' + } + compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java index 0ec1bb67..2df3c65d 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/activities/ViewSubredditDetailActivity.java @@ -690,9 +690,8 @@ public class ViewSubredditDetailActivity extends BaseActivity implements SortTyp qualifiedName = LemmyUtils.actorID2FullName(communityData.getActorId()); if (communityName == null) { communityName = communityData.getTitle(); - - setupVisibleElements(); } + setupVisibleElements(); communityId = communityData.getId(); setupSubscribeChip(); diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/fragments/SidebarFragment.java b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/SidebarFragment.java index 828db965..97eda348 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/fragments/SidebarFragment.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/fragments/SidebarFragment.java @@ -40,6 +40,7 @@ import eu.toldi.infinityforlemmy.markdown.MarkdownUtils; import eu.toldi.infinityforlemmy.subreddit.FetchSubredditData; import eu.toldi.infinityforlemmy.subreddit.SubredditData; import eu.toldi.infinityforlemmy.subreddit.SubredditViewModel; +import eu.toldi.infinityforlemmy.utils.LemmyUtils; import io.noties.markwon.AbstractMarkwonPlugin; import io.noties.markwon.Markwon; import io.noties.markwon.MarkwonConfiguration; @@ -97,7 +98,7 @@ public class SidebarFragment extends Fragment { mAccessToken = getArguments().getString(EXTRA_ACCESS_TOKEN); subredditName = getArguments().getString(EXTRA_SUBREDDIT_NAME); communityQualifiedName = getArguments().getString(EXTRA_COMMUNITY_QUALIFIED_NAME); - if (subredditName == null) { + if (communityQualifiedName == null) { Toast.makeText(activity, R.string.error_getting_community_name, Toast.LENGTH_SHORT).show(); return rootView; } @@ -166,7 +167,7 @@ public class SidebarFragment extends Fragment { }); mSubredditViewModel = new ViewModelProvider(activity, - new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, communityQualifiedName)) + new SubredditViewModel.Factory(activity.getApplication(), mRedditDataRoomDatabase, LemmyUtils.qualifiedCommunityName2ActorId(communityQualifiedName))) .get(SubredditViewModel.class); mSubredditViewModel.getSubredditLiveData().observe(getViewLifecycleOwner(), subredditData -> { if (subredditData != null) { diff --git a/app/src/main/java/eu/toldi/infinityforlemmy/markdown/MarkdownUtils.java b/app/src/main/java/eu/toldi/infinityforlemmy/markdown/MarkdownUtils.java index 529333a4..691d2737 100644 --- a/app/src/main/java/eu/toldi/infinityforlemmy/markdown/MarkdownUtils.java +++ b/app/src/main/java/eu/toldi/infinityforlemmy/markdown/MarkdownUtils.java @@ -52,6 +52,7 @@ public class MarkdownUtils { .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(TableEntryPlugin.create(context)) .usePlugin(ClickableGlideImagesPlugin.create(context)) + .usePlugin(new MarkwonLemmyLinkPlugin()) .build(); } @@ -71,6 +72,7 @@ public class MarkdownUtils { .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) .usePlugin(TableEntryPlugin.create(context)) .usePlugin(GlideImagesPlugin.create(context)) + .usePlugin(new MarkwonLemmyLinkPlugin()) .build(); } diff --git a/app/src/main/kotlin/eu/toldi/infinityforlemmy/markdown/MarkwonLemmyLinkPlugin.kt b/app/src/main/kotlin/eu/toldi/infinityforlemmy/markdown/MarkwonLemmyLinkPlugin.kt new file mode 100644 index 00000000..5456f164 --- /dev/null +++ b/app/src/main/kotlin/eu/toldi/infinityforlemmy/markdown/MarkwonLemmyLinkPlugin.kt @@ -0,0 +1,88 @@ +package eu.toldi.infinityforlemmy.markdown + + +import android.text.Spannable +import android.text.SpannableStringBuilder +import android.text.style.URLSpan +import android.text.util.Linkify +import eu.toldi.infinityforlemmy.utils.LemmyUtils +import io.noties.markwon.* +import io.noties.markwon.core.CorePlugin +import io.noties.markwon.core.CoreProps +import org.commonmark.node.Link +import java.util.regex.Pattern + +// Source : https://github.com/dessalines/jerboa/blob/main/app/src/main/java/com/jerboa/util/markwon/MarkwonLemmyLinkPlugin.kt +class MarkwonLemmyLinkPlugin : AbstractMarkwonPlugin() { + + companion object { + /** + * pattern that matches all valid communities; intended to be loose + */ + const val communityPatternFragment: String = """[a-zA-Z0-9_]{3,}""" + + /** + * pattern to match all valid instances + */ + const val instancePatternFragment: String = + """([a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]\.)+[a-zA-Z]{2,}""" + + /** + * pattern to match all valid usernames + */ + const val userPatternFragment: String = """[a-zA-Z0-9_]{3,}""" + + /** + * Pattern to match lemmy's unique community pattern, e.g. !commmunity[@instance] + */ + val lemmyCommunityPattern: Pattern = + Pattern.compile("(?The instance field cannot be left empty. The username field cannot be left empty. The password field cannot be left empty. + + Hello blank fragment diff --git a/build.gradle b/build.gradle index 754b079d..4eb65b79 100644 --- a/build.gradle +++ b/build.gradle @@ -9,6 +9,7 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:7.4.2' + classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.20' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files