Skip to content

Commit

Permalink
Blog screen
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalyster committed Jan 11, 2023
1 parent 7d19270 commit db52ac0
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/com/juick/android/JuickMessageMenuListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/com/juick/android/screens/blog/BlogFragment.kt
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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<BlogFragmentArgs>()

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
vm = ViewModelProvider(this, BlogViewModelFactory(args.uname))[BlogViewModel::class.java]
super.onViewCreated(view, savedInstanceState)
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/juick/android/screens/blog/BlogViewModel.kt
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

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 <T : ViewModel> create(modelClass: Class<T>): T {
return modelClass.getConstructor(String::class.java)
.newInstance(userName)
}
}
8 changes: 8 additions & 0 deletions src/main/res/navigation/navigation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,12 @@
tools:layout="@layout/fragment_tags_list"
android:name="com.juick.android.screens.post.TagsFragment"
android:label="@string/tags" />
<fragment
android:id="@+id/blog"
android:name="com.juick.android.screens.blog.BlogFragment"
android:label="{uname}" >
<argument
android:name="uname"
app:argType="string" />
</fragment>
</navigation>

0 comments on commit db52ac0

Please sign in to comment.