diff --git a/src/main/java/com/juick/android/JuickMessageMenuListener.kt b/src/main/java/com/juick/android/JuickMessageMenuListener.kt index c4da1ead..60b52aa0 100644 --- a/src/main/java/com/juick/android/JuickMessageMenuListener.kt +++ b/src/main/java/com/juick/android/JuickMessageMenuListener.kt @@ -30,6 +30,7 @@ import com.juick.App import com.juick.R import com.juick.android.fragment.ThreadFragmentArgs import com.juick.android.screens.FeedAdapter +import com.juick.android.screens.blog.BlogFragmentArgs import com.juick.api.model.Post import com.juick.api.model.User import kotlinx.coroutines.launch @@ -103,6 +104,10 @@ class JuickMessageMenuListener( val uname = post.user.uname when (action) { MENU_ACTION_BLOG -> { + val navController = Navigation.findNavController(view) + val args = BlogFragmentArgs.Builder(uname) + .build() + navController.navigate(R.id.blog, args.toBundle()) true } MENU_ACTION_RECOMMEND -> confirmAction( diff --git a/src/main/java/com/juick/android/screens/blog/BlogFragment.kt b/src/main/java/com/juick/android/screens/blog/BlogFragment.kt new file mode 100644 index 00000000..5db44aac --- /dev/null +++ b/src/main/java/com/juick/android/screens/blog/BlogFragment.kt @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2008-2023, Juick + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.juick.android.screens.blog + +import android.os.Bundle +import android.view.View +import androidx.lifecycle.ViewModelProvider +import androidx.navigation.fragment.navArgs +import com.juick.android.screens.FeedFragment + +class BlogFragment : FeedFragment() { + private val args by navArgs() + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + vm = ViewModelProvider(this, BlogViewModelFactory(args.uname))[BlogViewModel::class.java] + super.onViewCreated(view, savedInstanceState) + } +} \ No newline at end of file diff --git a/src/main/java/com/juick/android/screens/blog/BlogViewModel.kt b/src/main/java/com/juick/android/screens/blog/BlogViewModel.kt new file mode 100644 index 00000000..1357a9a2 --- /dev/null +++ b/src/main/java/com/juick/android/screens/blog/BlogViewModel.kt @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2008-2023, Juick + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.juick.android.screens.blog + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.ViewModelProvider +import com.juick.android.UrlBuilder +import com.juick.android.screens.FeedViewModel + +class BlogViewModel(name: String) : FeedViewModel() { + init { + apiUrl.value = (UrlBuilder.getUserPostsByName(name).toString()) + } +} + +class BlogViewModelFactory(private val userName: String): ViewModelProvider.Factory { + override fun create(modelClass: Class): T { + return modelClass.getConstructor(String::class.java) + .newInstance(userName) + } +} \ No newline at end of file diff --git a/src/main/res/navigation/navigation.xml b/src/main/res/navigation/navigation.xml index dc032caa..4efb8859 100644 --- a/src/main/res/navigation/navigation.xml +++ b/src/main/res/navigation/navigation.xml @@ -122,4 +122,12 @@ tools:layout="@layout/fragment_tags_list" android:name="com.juick.android.screens.post.TagsFragment" android:label="@string/tags" /> + + + \ No newline at end of file