Skip to content

Commit

Permalink
added badges in profile screen + Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Feb 8, 2018
1 parent 344731d commit 31d0649
Show file tree
Hide file tree
Showing 44 changed files with 486 additions and 39 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ dependencies {
// Glide
implementation "com.github.bumptech.glide:glide:$versions.glide"
kapt "com.github.bumptech.glide:compiler:$versions.glide"
implementation "com.github.bumptech.glide:okhttp3-integration:$versions.glide"
implementation 'com.google.code.gson:gson:2.8.2'

// Leak Canary
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
</activity>
<activity android:name=".ui.modules.links.related.RelatedActivity" />
<activity android:name=".ui.modules.profile.ProfileActivity" />
<activity android:name=".ui.modules.notificationslist.NotificationsListActivity" />

<receiver android:name=".ui.modules.notifications.notificationsservice.WykopNotificationsBroadcastReceiver">
<intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.feelfreelinux.wykopmobilny.api.profile
import io.github.feelfreelinux.wykopmobilny.models.dataclass.*
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.ObserveStateResponse
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.ProfileResponse
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.responses.BadgeResponse
import io.reactivex.Single

interface ProfileApi {
Expand All @@ -16,6 +17,7 @@ interface ProfileApi {
fun getEntries(username : String, page : Int) : Single<List<Entry>>
fun getEntriesComments(username : String, page : Int) : Single<List<EntryComment>>
fun getRelated(username : String, page : Int) : Single<List<Related>>
fun getBadges(username : String, page : Int): Single<List<BadgeResponse>>

fun observe(tag: String): Single<ObserveStateResponse>
fun unobserve(tag: String): Single<ObserveStateResponse>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.github.feelfreelinux.wykopmobilny.api.notifications.NotificationsRetro
import io.github.feelfreelinux.wykopmobilny.models.dataclass.*
import io.github.feelfreelinux.wykopmobilny.models.mapper.apiv2.*
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.*
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.responses.BadgeResponse
import io.github.feelfreelinux.wykopmobilny.utils.LinksPreferencesApi
import io.reactivex.Single
import retrofit2.Retrofit
Expand Down Expand Up @@ -66,6 +67,12 @@ class ProfileRepository(val retrofit: Retrofit, val userTokenRefresher: UserToke
.compose<List<LinkResponse>>(ErrorHandlerTransformer())
.map { it.map { LinkMapper.map(it, linksPreferencesApi) } }

override fun getBadges(username: String, page: Int): Single<List<BadgeResponse>> =
profileApi.getBadges(username, page)
.retryWhen(userTokenRefresher)
.compose<List<BadgeResponse>>(ErrorHandlerTransformer())


override fun getRelated(username: String, page: Int): Single<List<Related>> =
profileApi.getRelated(username, page)
.retryWhen(userTokenRefresher)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.feelfreelinux.wykopmobilny.api.profile
import io.github.feelfreelinux.wykopmobilny.APP_KEY
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.common.WykopApiResponse
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.models.*
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.responses.BadgeResponse
import io.reactivex.Single
import retrofit2.http.GET
import retrofit2.http.Path
Expand Down Expand Up @@ -48,4 +49,8 @@ interface ProfileRetrofitApi {
fun block(@Path("username") username : String) : Single<WykopApiResponse<ObserveStateResponse>>

@GET("/profiles/unblock/{username}/appkey/$APP_KEY")
fun unblock(@Path("username") username : String) : Single<WykopApiResponse<ObserveStateResponse>>}
fun unblock(@Path("username") username : String) : Single<WykopApiResponse<ObserveStateResponse>>

@GET("/profiles/badges/{username}/page/{page}/appkey/$APP_KEY")
fun getBadges(@Path("username") username : String, @Path("page") page: Int) : Single<WykopApiResponse<List<BadgeResponse>>>
}
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import io.github.feelfreelinux.wykopmobilny.ui.modules.mainnavigation.MainNaviga
import io.github.feelfreelinux.wykopmobilny.ui.modules.mikroblog.entry.EntryActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.mikroblog.entry.EntryDetailModule
import io.github.feelfreelinux.wykopmobilny.ui.modules.notifications.notificationsservice.WykopNotificationsBroadcastReceiver
import io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist.NotificationsListActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist.NotificationsListFragmentProvider
import io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist.NotificationsListModule
import io.github.feelfreelinux.wykopmobilny.ui.modules.photoview.PhotoViewActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.pm.conversation.ConversationActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.pm.conversation.ConversationActivityModule
Expand Down Expand Up @@ -92,4 +95,7 @@ abstract class ActivityBuilder {

@ContributesAndroidInjector(modules = [LinkCommentEditModule::class])
abstract fun bindLinkEditCommentActivity() : LinkCommentEditActivity

@ContributesAndroidInjector(modules = [NotificationsListFragmentProvider::class, NotificationsListModule::class])
abstract fun bindNotificationsActivity() : NotificationsListActivity
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
package io.github.feelfreelinux.wykopmobilny.glide

import android.content.Context
import com.bumptech.glide.Glide
import com.bumptech.glide.Registry
import com.bumptech.glide.annotation.GlideModule
import com.bumptech.glide.integration.okhttp3.OkHttpUrlLoader
import com.bumptech.glide.load.model.GlideUrl
import com.bumptech.glide.module.AppGlideModule
import okhttp3.OkHttpClient
import java.io.InputStream
import java.util.concurrent.TimeUnit

@GlideModule
class GlideModule : AppGlideModule()
class GlideModule : AppGlideModule() {
override fun registerComponents(context: Context?, glide: Glide?, registry: Registry?) {
val builder = OkHttpClient.Builder()
builder.readTimeout(15, TimeUnit.SECONDS)
builder.writeTimeout(15, TimeUnit.SECONDS)
builder.connectTimeout(15, TimeUnit.SECONDS)
registry?.append(GlideUrl::class.java, InputStream::class.java, OkHttpUrlLoader.Factory(builder.build()))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.responses

import com.squareup.moshi.Json

data class BadgeResponse(
@Json(name = "name")
val name : String,

@Json(name = "date")
val date : String,

@Json(name = "description")
val description : String,

@Json(name = "icon")
val icon : String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.feelfreelinux.wykopmobilny.ui.adapters

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.base.adapter.SimpleBaseProgressAdapter
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Upvoter
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.responses.BadgeResponse
import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.BadgeViewHolder
import io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders.UpvoterViewHolder
import javax.inject.Inject

class BadgeListAdapter : SimpleBaseProgressAdapter<BadgeViewHolder, BadgeResponse>() {
override fun createViewHolder(parent: ViewGroup): BadgeViewHolder
= BadgeViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.badge_list_item, parent, false))

override fun bindHolder(holder: BadgeViewHolder, position: Int) {
holder.bindView(data[position])
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders

import android.support.v7.widget.RecyclerView
import android.view.View
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Author
import io.github.feelfreelinux.wykopmobilny.models.pojo.apiv2.responses.BadgeResponse
import io.github.feelfreelinux.wykopmobilny.utils.loadImage
import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate
import kotlinx.android.synthetic.main.badge_list_item.view.*

class BadgeViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
fun bindView(badge : BadgeResponse) {
view.badgeTitle.text = badge.name
view.badgeImg.loadImage(badge.icon)
view.description.text = badge.description
view.date.text = badge.date.toPrettyDate()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.github.feelfreelinux.wykopmobilny.models.dataclass.Author
import io.github.feelfreelinux.wykopmobilny.models.dataclass.EntryComment
import io.github.feelfreelinux.wykopmobilny.ui.widgets.entry.comment.CommentPresenter
import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi
import io.github.feelfreelinux.wykopmobilny.utils.isVisible
import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi
import kotlinx.android.synthetic.main.comment_list_item.view.*
import kotlinx.android.synthetic.main.entry_comment_layout.view.*
Expand All @@ -22,6 +23,10 @@ class CommentViewHolder(val view: View, private val addReceiverListener : (Autho
override fun cleanRecycled() {
view.apply {
GlideApp.with(this).clear(view.entryComment.entryImageView)
view.entryComment.shouldEnableClickListener = false
view.entryComment.entryContentTextView.text = null
view.entryComment.addReceiverListener = null
view.entryComment.setOnClickListener(null)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Downvoter
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Upvoter
import io.github.feelfreelinux.wykopmobilny.ui.widgets.link.LinkPresenter
import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate
import kotlinx.android.synthetic.main.downvoters_list_item.view.*

class DownvoterViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
fun bindView(downvoter: Downvoter) {
view.authorHeaderView.setAuthorData(downvoter.author, downvoter.date)
view.authorHeaderView.setAuthorData(downvoter.author, downvoter.date.toPrettyDate())
view.reason_textview.text = when(downvoter.reason) {
LinkPresenter.BURY_REASON_DUPLICATE -> view.resources.getString(R.string.reason_duplicate)
LinkPresenter.BURY_REASON_SPAM -> view.resources.getString(R.string.reason_spam)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,4 @@ class LinkViewHolder(val view: View) : RecyclableViewHolder(view) {
GlideApp.with(this).clear(image)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package io.github.feelfreelinux.wykopmobilny.ui.adapters.viewholders
import android.support.v7.widget.RecyclerView
import android.view.View
import io.github.feelfreelinux.wykopmobilny.models.dataclass.Upvoter
import io.github.feelfreelinux.wykopmobilny.utils.toPrettyDate
import kotlinx.android.synthetic.main.conversation_list_item.view.*

class UpvoterViewHolder(val view: View) : RecyclerView.ViewHolder(view) {
fun bindView(upvoter: Upvoter) {
view.authorHeaderView.setAuthorData(upvoter.author, upvoter.date)
view.authorHeaderView.setAuthorData(upvoter.author, upvoter.date.toPrettyDate())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.github.feelfreelinux.wykopmobilny.ui.modules.links.linkdetails.LinkDet
import io.github.feelfreelinux.wykopmobilny.ui.modules.loginscreen.LoginScreenActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.mainnavigation.MainNavigationActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.mikroblog.entry.EntryActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist.NotificationsListActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.photoview.PhotoViewActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.pm.conversation.ConversationActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.settings.SettingsActivity
Expand Down Expand Up @@ -96,4 +97,8 @@ class Navigator : NavigatorApi {
override fun openLinkDetailsActivity(context: Activity, link : Link) {
context.startActivity(LinkDetailsActivity.createIntent(context, link))
}

fun openNotificationsListActivity(context : Activity) {
context.startActivity(NotificationsListActivity.createIntent(context))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.github.feelfreelinux.wykopmobilny.ui.modules.links.upvoters.UpvotersAc
import io.github.feelfreelinux.wykopmobilny.ui.modules.loginscreen.LoginScreenActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.mainnavigation.MainNavigationActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.mikroblog.entry.EntryActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist.NotificationsListActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.photoview.PhotoViewActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.pm.conversation.ConversationActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.profile.ProfileActivity
Expand Down Expand Up @@ -45,7 +46,7 @@ interface NewNavigatorApi {
fun openLinkDownvotersActivity(linkId : Int)
fun openLinkRelatedActivity(linkId : Int)
fun openProfileActivity(username : String)

fun openNotificationsListActivity(preselectIndex : Int = NotificationsListActivity.PRESELECT_NOTIFICATIONS)
}

class NewNavigator(val context : Activity) : NewNavigatorApi {
Expand Down Expand Up @@ -128,4 +129,8 @@ class NewNavigator(val context : Activity) : NewNavigatorApi {
override fun openProfileActivity(username: String) {
context.startActivity(ProfileActivity.createIntent(context, username))
}

override fun openNotificationsListActivity(preselectIndex: Int) {
context.startActivity(NotificationsListActivity.createIntent(context, preselectIndex))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class HitsFragment : BaseFragment(), HitsView {
R.id.byMonth -> {
val pickerFragment = MonthYearPickerDialog.newInstance(presenter.monthSelection, presenter.yearSelection)
pickerFragment.setTargetFragment(this, PICKER_REQUEST_CODE)
pickerFragment.show(childFragmentManager, "pickerDialogFragment")
pickerFragment.show(supportFragmentManager, "pickerDialogFragment")
setTitle()
}

Expand All @@ -90,7 +90,7 @@ class HitsFragment : BaseFragment(), HitsView {
R.id.byYear -> {
val pickerFragment = YearPickerDialog.newInstance(presenter.yearSelection)
pickerFragment.setTargetFragment(this, PICKER_REQUEST_CODE)
pickerFragment.show(childFragmentManager, "pickerDialogFragment")
pickerFragment.show(supportFragmentManager, "pickerDialogFragment")
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.github.feelfreelinux.wykopmobilny.ui.modules.loginscreen.LoginScreenAc
import io.github.feelfreelinux.wykopmobilny.ui.modules.mikroblog.feed.hot.HotFragment
import io.github.feelfreelinux.wykopmobilny.ui.modules.mywykop.MyWykopFragment
import io.github.feelfreelinux.wykopmobilny.ui.modules.notifications.notificationsservice.WykopNotificationsJob
import io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist.NotificationsListActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist.hashtags.HashTagsNotificationsListFragment
import io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist.notification.NotificationsListFragment
import io.github.feelfreelinux.wykopmobilny.ui.modules.pm.conversationslist.ConversationsListFragment
Expand Down Expand Up @@ -208,13 +209,13 @@ class MainNavigationActivity : BaseActivity(), MainNavigationView, NavigationVie
navHeader.view_container.isVisible = value
navHeader.view_container.apply {
nav_notifications_tag.setOnClickListener {
openFragment(HashTagsNotificationsListFragment.newInstance())
deselectItems()
navigator.openNotificationsListActivity(NotificationsListActivity.PRESELECT_HASHTAGS)
}

nav_notifications.setOnClickListener {
openFragment(NotificationsListFragment.newInstance())
deselectItems()
navigator.openNotificationsListActivity(NotificationsListActivity.PRESELECT_NOTIFICATIONS)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.ui.modules.mainnavigation.MainNavigationActivity
import io.github.feelfreelinux.wykopmobilny.ui.modules.notifications.WykopNotificationManager
import io.github.feelfreelinux.wykopmobilny.ui.modules.notifications.WykopNotificationManagerApi
import io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist.NotificationsListActivity
import io.github.feelfreelinux.wykopmobilny.utils.SettingsPreferencesApi
import io.github.feelfreelinux.wykopmobilny.utils.wykop_link_handler.WykopLinkHandler
import java.util.concurrent.TimeUnit
Expand Down Expand Up @@ -80,7 +81,7 @@ class WykopNotificationsJob(
override fun showNotificationsCount(count: Int) {
if (settingsApi.showNotifications) {
// Create intent
val intent = MainNavigationActivity.getIntent(context, MainNavigationActivity.TARGET_NOTIFICATIONS)
val intent = NotificationsListActivity.createIntent(context)
intent.action = System.currentTimeMillis().toString()
intent.flags = (Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
val pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.feelfreelinux.wykopmobilny.ui.modules.notificationslist

import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.base.BaseActivity
import kotlinx.android.synthetic.main.activity_notifications.*
import kotlinx.android.synthetic.main.toolbar.*


class NotificationsListActivity : BaseActivity() {
companion object {
val EXTRA_PRESELECT_INDEX = "PRESELECT_INDEX"
val PRESELECT_NOTIFICATIONS = 0
val PRESELECT_HASHTAGS = 1
fun createIntent(context : Context, currentIndex : Int = PRESELECT_NOTIFICATIONS) : Intent {
val intent = Intent(context, NotificationsListActivity::class.java)
intent.putExtra(EXTRA_PRESELECT_INDEX, currentIndex)
return intent
}
}
val pagerAdapter by lazy { NotificationsListViewPagerAdapter(resources, supportFragmentManager) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_notifications)
setSupportActionBar(toolbar)
supportActionBar?.setTitle(R.string.notifications_title)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
pager.offscreenPageLimit = 1
pager.adapter = pagerAdapter
pager.setCurrentItem(intent.getIntExtra(EXTRA_PRESELECT_INDEX, 0), false)
tabLayout.setupWithViewPager(pager)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
when(item.itemId) {
android.R.id.home -> { finish() }
}
return true
}
}
Loading

0 comments on commit 31d0649

Please sign in to comment.