Skip to content

Commit

Permalink
Bug fixes, reworked drawer header
Browse files Browse the repository at this point in the history
  • Loading branch information
feelfreelinux committed Nov 18, 2017
1 parent a3d7d7a commit 9230493
Show file tree
Hide file tree
Showing 19 changed files with 123 additions and 67 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ before_script:
- echo -e "apiKey=\"$wykopApiKey\"\napiSecret=\"$wykopApiSecret\"" >> credentials.properties
script:
- "./gradlew assembleRelease"
before_deploy:
- mv app/build/outputs/apk/release/app-release.apk app/build/outputs/apk/release/wykopmobilny-$TRAVIS_TAG.apk
deploy:
provider: releases
api_key:
secure: mh793ORwYZxd0CERyAYUlyhCeLhCMtvZeklvGrZ4Q6AK8cnacNsg41rOoIK1K1pAqBntXEVLBC3cRg2rAPy0nRT45z3wduUAnDFgvay4lV7FaTO0QwWT8rYWfyWfjEY3Ti13NV+wBa+wF25W6Cr2PNjdge3lVGnck0Xo52X2eMAOuWJMI1Jb2p1QLBAjenPYyh6uSBX8ZScZN0Jx3KVQeFyCoLHwULP8wjVIbTgFbF3qHPNV0l6FZZh7B9WOvHavSk17SDeTD655VoA57vZ/MCBkruwvGmuzs5tixko15kd6+r/mS6DN5NMWlLDODrrTk9xuEYhO8i26bJKwOlSol1A8Ff9vPrVPayp5lbhbdMXJJkeMkDrHG76ugNzeJhJCm67tlq43COUFuin5L8QpC4iOLy3TjOluzkhIn6pZ6OOdsfG3Ip/BpwR+yb+pfaPhiZ1fvuqfDza2ina8bWbYksUoD1AKRDvd1sAg9XqYGxlaxXoL0BeZqTKUwToziaNES2/pGRKNBhM8B+YZyrNYasDPZzKhIWsx6jaXWos3vy7G1JpE8e7xzw/wlemD7fU+/O/hTUaSOtJLCWwoAP3rI42rZEpuAPAZ9aNvtA3PmZUssuZzeEH3zyAU4LhSXE2YH82lRph/sDZjbOnfTo8Sbho/G334gARb15d34YmareU=
file: app/build/outputs/apk/release/app-release.apk
file: app/build/outputs/apk/release/wykopmobilny-$TRAVIS_TAG.apk
skip_cleanup: true
on:
all_branches: true
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ android {
applicationId "io.github.feelfreelinux.wykopmobilny"
minSdkVersion 17
targetSdkVersion 26
versionCode 6
versionName "0.2.1"
versionCode 7
versionName "0.2.2"

def credentialsPropertiesFile = rootProject.file("credentials.properties")
def credentialsProperties = new Properties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ data class Notification(
val body : String,
val date : String,
val type : String,
val url : String,
val url : String?,
var new : Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data class NotificationResponse(
@Json(name = "item_id")
val itemId : String?,
@Json(name = "url")
val url : String,
val url : String?,
@Json(name = "new")
val new : Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fun ExceptionDialog(context : Context, e: Throwable) : AlertDialog? {
alertBuilder.run {
setTitle(context.getString(R.string.error_occured))
setMessage(message)
setNeutralButton(android.R.string.ok, null)
return create()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ class NavigationActivity : BaseActivity(), MainNavigationView, NavigationView.On
.setGitHubUserAndRepo("feelfreelinux", "WykopMobilny")
.setTitleOnUpdateAvailable(R.string.update_available)
.setContentOnUpdateAvailable(R.string.update_app)
.setButtonDismiss(R.string.cancel)
.setButtonDoNotShowAgain(R.string.do_not_show_again)
.setButtonUpdate(R.string.update)
.start()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import io.github.feelfreelinux.wykopmobilny.ui.adapters.decorators.EntryCommentI
import io.github.feelfreelinux.wykopmobilny.ui.dialogs.ExitConfirmationDialog
import io.github.feelfreelinux.wykopmobilny.ui.modules.input.BaseInputActivity
import io.github.feelfreelinux.wykopmobilny.ui.widgets.InputToolbarListener
import io.github.feelfreelinux.wykopmobilny.utils.ClipboardHelperApi
import io.github.feelfreelinux.wykopmobilny.utils.isVisible
import io.github.feelfreelinux.wykopmobilny.utils.prepare
import io.github.feelfreelinux.wykopmobilny.utils.wykop_link_handler.linkparser.EntryLinkParser
Expand All @@ -41,6 +42,7 @@ class EntryActivity : BaseActivity(), EntryDetailView, InputToolbarListener, Swi
}
}

@Inject lateinit var clipboardHelper : ClipboardHelperApi
@Inject lateinit var presenter: EntryDetailPresenter
private lateinit var entryFragmentData: DataFragment<Entry>
private val adapter by lazy { EntryDetailAdapter({ inputToolbar.addAddressant(it.nick) }) }
Expand Down Expand Up @@ -114,6 +116,14 @@ class EntryActivity : BaseActivity(), EntryDetailView, InputToolbarListener, Swi
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
android.R.id.home -> onBackPressed()
R.id.copyUrl -> clipboardHelper.copyTextToClipboard(url, "entryUrl")
R.id.share -> {
val i = Intent(Intent.ACTION_SEND)
i.type = "text/plain"
i.putExtra(Intent.EXTRA_SUBJECT, resources.getString(R.string.share))
i.putExtra(Intent.EXTRA_TEXT, url)
startActivity(Intent.createChooser(i, resources.getString(R.string.share)))
}
}
return true
}
Expand Down Expand Up @@ -180,4 +190,7 @@ class EntryActivity : BaseActivity(), EntryDetailView, InputToolbarListener, Swi
}
}
}

val url : String
get() = "https://wykop.pl/wpis/$entryId"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ class WykopNotificationsJob : Job(), WykopNotificationsJobView {
}

override fun showNotification(notification: io.github.feelfreelinux.wykopmobilny.models.dataclass.Notification) {
val intent = wykopLinkHandler.getLinkIntent(context, notification.url)
val intent = wykopLinkHandler.getLinkIntent(context, notification.url!!)

val pendingIntent = if (intent != null) {
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
PendingIntent.getActivity(context, 0, intent, 0)

} else {
Expand All @@ -79,7 +79,7 @@ class WykopNotificationsJob : Job(), WykopNotificationsJobView {
override fun showNotificationsCount(count: Int) {
// Create intent
val intent = NavigationActivity.getIntent(context, NavigationActivity.TARGET_NOTIFICATIONS)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
val pendingIntent = PendingIntent.getActivity(context, 0, intent, 0)

// Show Notification
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ abstract class BaseNotificationsListFragment : BaseFragment(), NotificationsList
val notification = notificationAdapter.data[position]
notification.new = false
notificationAdapter.notifyDataSetChanged()
linkHandler.handleUrl(activity, notification.url)
notification.url?.let {
linkHandler.handleUrl(activity, notification.url)
}
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,25 @@ class DrawerHeaderPresenter(val subscriptionHelper: SubscriptionHelperApi,
}

private fun getNotificationsCount(single: Single<NotificationsCountResponse>) {
subscriptionHelper.subscribe(single,
{ view?.notificationCount = it.count },
{ view?.showErrorDialog(it) },
this@DrawerHeaderPresenter)
view?.let {
if (view!!.isConnectedToInternet) {
subscriptionHelper.subscribe(single,
{ view?.notificationCount = it.count },
{ view?.showErrorDialog(it) },
this@DrawerHeaderPresenter)
}
}
}

private fun getHashTagNotificationsCount(single: Single<NotificationsCountResponse>) {
subscriptionHelper.subscribe(single,
{ view?.hashTagsNotificationsCount = it.count },
{ view?.showErrorDialog(it) },
this@DrawerHeaderPresenter)
view?.let {
if (view!!.isConnectedToInternet) {
subscriptionHelper.subscribe(single,
{ view?.hashTagsNotificationsCount = it.count },
{ view?.showErrorDialog(it) },
this@DrawerHeaderPresenter)
}
}
}

override fun unsubscribe() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import io.github.feelfreelinux.wykopmobilny.base.BaseView
interface DrawerHeaderView : BaseView {
var notificationCount : Int
var hashTagsNotificationsCount : Int
val isConnectedToInternet : Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import android.view.View
import io.github.feelfreelinux.wykopmobilny.R
import io.github.feelfreelinux.wykopmobilny.WykopApp
import io.github.feelfreelinux.wykopmobilny.ui.dialogs.showExceptionDialog
import io.github.feelfreelinux.wykopmobilny.utils.isVisible
import io.github.feelfreelinux.wykopmobilny.utils.loadImage
import io.github.feelfreelinux.wykopmobilny.utils.printout
import io.github.feelfreelinux.wykopmobilny.utils.*
import io.github.feelfreelinux.wykopmobilny.utils.usermanager.UserManagerApi
import kotlinx.android.synthetic.main.drawer_header_view_layout.view.*
import javax.inject.Inject
Expand All @@ -21,6 +19,9 @@ class DrawerHeaderWidget : ConstraintLayout, DrawerHeaderView {

constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

// @TODO Put this in memory
val PLACEHOLDER_IMAGE_URL = "https://i.imgur.com/aSm6pSJ.jpg"

@Inject lateinit var userManager : UserManagerApi
@Inject lateinit var presenter : DrawerHeaderPresenter

Expand All @@ -40,7 +41,13 @@ class DrawerHeaderWidget : ConstraintLayout, DrawerHeaderView {
private fun checkIsUserLoggedIn() {
if (userManager.isUserAuthorized()) {
isVisible = true
img_profile.loadImage(userManager.getUserCredentials()!!.avatarUrl)
val credentials = userManager.getUserCredentials()!!
nav_profile_image.loadImage(credentials.avatarUrl)
if (credentials.backgroundUrl != null) {
backgroundImage.loadImage(credentials.backgroundUrl)
} else {
backgroundImage.loadImage(PLACEHOLDER_IMAGE_URL)
}
presenter.fetchNotifications()
} else {
isVisible = false
Expand Down Expand Up @@ -71,5 +78,8 @@ class DrawerHeaderWidget : ConstraintLayout, DrawerHeaderView {
checkIsUserLoggedIn()
}

override val isConnectedToInternet : Boolean
get() = context.isConnectedToInternet()

override fun showErrorDialog(e: Throwable) = context.showExceptionDialog(e)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,24 @@ import android.content.Context
import android.net.Uri
import android.support.customtabs.CustomTabsIntent
import io.github.feelfreelinux.wykopmobilny.R
import android.net.NetworkInfo
import android.net.ConnectivityManager



fun Context.openBrowser(url : String) {
// Start in-app browser, handled by Chrome Customs Tabs
val builder = CustomTabsIntent.Builder()
val customTabsIntent = builder.build()
builder.setToolbarColor(R.attr.colorPrimaryDark)
customTabsIntent.launchUrl(this, Uri.parse(url))
}
}

fun Context.isConnectedToInternet(): Boolean {

val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

val activeNetwork = cm.activeNetworkInfo

return activeNetwork != null && activeNetwork.isConnected
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ interface CredentialsPreferencesApi {
var userKey: String?
var userToken: String?
var avatarUrl: String?
var backgroundUrl : String?
var timeStamp: String?
}

Expand All @@ -16,6 +17,7 @@ class CredentialsPreferences(context: Context) : Preferences(context), Credentia
override var userKey by stringPref(defaultValue = "")
override var userToken by stringPref(defaultValue = "")
override var avatarUrl by stringPref(defaultValue = "")
override var backgroundUrl by stringPref(defaultValue = "")
override var timeStamp by stringPref(defaultValue = "")

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fun TextView.prepareBody(html: String, listener : URLClickedListener) {
context.createAlertBuilder().apply {
setTitle("Spoiler")
setMessage(URLDecoder.decode(text, "UTF-8"))
setNeutralButton(android.R.string.ok, null)
create().show()
}
} else listener.handleUrl(url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.github.feelfreelinux.wykopmobilny.utils.api.CredentialsPreferencesApi

data class LoginCredentials(val login : String, val token : String)

data class UserCredentials(val login : String, val avatarUrl : String, val userKey : String)
data class UserCredentials(val login : String, val avatarUrl : String, val backgroundUrl : String?, val userKey : String)

interface UserManagerApi {
fun loginUser(credentials : LoginCredentials)
Expand Down Expand Up @@ -37,6 +37,7 @@ class UserManager(private val credentialsPreferencesApi: CredentialsPreferencesA
override fun saveCredentials(credentials : LoginResponse) {
credentialsPreferencesApi.apply {
avatarUrl = credentials.profile.avatar
backgroundUrl = credentials.profile.background
userToken = credentials.userkey
}
}
Expand All @@ -50,7 +51,7 @@ class UserManager(private val credentialsPreferencesApi: CredentialsPreferencesA
override fun getUserCredentials(): UserCredentials? {
credentialsPreferencesApi.run {
return if (!login.isNullOrEmpty() || !avatarUrl.isNullOrEmpty() || !userToken.isNullOrEmpty()) {
UserCredentials(login!!, avatarUrl!!, userToken!!)
UserCredentials(login!!, avatarUrl!!, backgroundUrl, userToken!!)
} else null
}
}
Expand Down
81 changes: 39 additions & 42 deletions app/src/main/res/layout/drawer_header_view_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,52 @@
android:layout_width="match_parent">

<ImageView
android:id="@+id/img_profile"
android:layout_width="90dp"
android:layout_height="90dp"
android:layout_margin="5dp"
android:id="@+id/backgroundImage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
app:layout_constraintEnd_toEndOf="parent" />

<ImageView
android:id="@+id/nav_profile_image"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:paddingTop="@dimen/nav_header_vertical_spacing"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/nav_notifications"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:drawableStart="?attr/mailDrawable"
android:theme="@style/NavigationDrawerNotificationItem"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/img_profile"
app:layout_constraintTop_toTopOf="@+id/img_profile" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="80dp"
android:gravity="center_vertical"
app:layout_constraintTop_toTopOf="@id/nav_profile_image"
app:layout_constraintStart_toEndOf="@id/nav_profile_image"
android:paddingEnd="8dp"
android:paddingStart="8dp"
android:background="?attr/cardListColor"
android:orientation="vertical">
<TextView
android:id="@+id/nav_notifications"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="?attr/mailDrawable"
android:theme="@style/NavigationDrawerNotificationItem" />
<View
android:id="@+id/spacer"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="?attr/spacerColor" />

<TextView
android:id="@+id/nav_notifications_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableStart="?attr/notificationDrawable"
android:theme="@style/NavigationDrawerNotificationItem"/>
</LinearLayout>

<View
android:id="@+id/spacer"
android:layout_width="0dp"
android:layout_height="2dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="?attr/spacerColor"
app:layout_constraintBottom_toTopOf="@+id/nav_notifications_tag"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/img_profile"
app:layout_constraintTop_toBottomOf="@+id/nav_notifications" />

<TextView
android:id="@+id/nav_notifications_tag"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:drawableStart="?attr/notificationDrawable"
android:theme="@style/NavigationDrawerNotificationItem"
app:layout_constraintBottom_toBottomOf="@+id/img_profile"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/img_profile" />
</merge>

0 comments on commit 9230493

Please sign in to comment.