This repository has been archived by the owner on Jan 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New : User profile + logout (trello.com/c/9eFy2Z4p)
- Loading branch information
1 parent
4d24e1a
commit b5c92f0
Showing
14 changed files
with
340 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
app/src/main/kotlin/com/dawnimpulse/wallup/activities/UserActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
ISC License | ||
Copyright 2018, Saksham (DawnImpulse) | ||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, | ||
provided that the above copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | ||
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE | ||
OR PERFORMANCE OF THIS SOFTWARE.*/ | ||
package com.dawnimpulse.wallup.activities | ||
|
||
import android.content.DialogInterface | ||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.core.widget.toast | ||
import com.dawnimpulse.wallup.R | ||
import com.dawnimpulse.wallup.handlers.ImageHandler | ||
import com.dawnimpulse.wallup.models.UnsplashModel | ||
import com.dawnimpulse.wallup.pojo.UserPojo | ||
import com.dawnimpulse.wallup.utils.C | ||
import com.dawnimpulse.wallup.utils.Config | ||
import com.dawnimpulse.wallup.utils.Dialog | ||
import com.dawnimpulse.wallup.utils.L | ||
import com.google.gson.Gson | ||
import com.pixplicity.easyprefs.library.Prefs | ||
import kotlinx.android.synthetic.main.activity_user.* | ||
|
||
/** | ||
* @author Saksham | ||
* | ||
* @note Last Branch Update - master | ||
* @note Created on 2018-10-04 by Saksham | ||
* | ||
* @note Updates : | ||
*/ | ||
class UserActivity : AppCompatActivity() { | ||
private val NAME = "UserActivity" | ||
private lateinit var model: UnsplashModel | ||
|
||
// on create | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_user) | ||
|
||
// fetching details from prefs | ||
if (Prefs.contains(C.USER)) | ||
setDetails(Gson().fromJson(Prefs.getString(C.USER, ""), UserPojo::class.java)) | ||
|
||
// fetching details from unsplash | ||
model = UnsplashModel(lifecycle) | ||
model.selfProfile() { e, r -> | ||
e?.let { | ||
L.d(NAME, e) | ||
toast("error fetching profile") | ||
} | ||
r?.let { | ||
Prefs.putString(C.USER, Gson().toJson(it)) | ||
setDetails(it as UserPojo) | ||
} | ||
|
||
} | ||
|
||
// logout user | ||
logoutL.setOnClickListener { | ||
Dialog.simpleOk(this, | ||
"User Profile Logout", | ||
"Wish to logout from your profile ?", | ||
DialogInterface.OnClickListener { dialog, _ -> | ||
Prefs.remove(C.USER_TOKEN) | ||
Prefs.remove(C.USER) | ||
Config.USER_API_KEY = "" | ||
dialog.dismiss() | ||
toast("Successfully logout from your profile") | ||
finish() | ||
}) | ||
} | ||
} | ||
|
||
//set user details | ||
private fun setDetails(user: UserPojo) { | ||
userFullName.text = user.name | ||
userName.text = "@${user.username}" | ||
ImageHandler.setImageInView(lifecycle, userImage, user.profile_image.large) | ||
ImageHandler.setImageInView(lifecycle, userBg, "${C.UNSPLASH_SOURCE}/user/${user.username}/720x1280") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
app/src/main/kotlin/com/dawnimpulse/wallup/utils/Dialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
ISC License | ||
Copyright 2018, Saksham (DawnImpulse) | ||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, | ||
provided that the above copyright notice and this permission notice appear in all copies. | ||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, | ||
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | ||
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE | ||
OR PERFORMANCE OF THIS SOFTWARE.*/package com.dawnimpulse.wallup.utils | ||
|
||
import android.content.Context | ||
import android.content.DialogInterface | ||
import androidx.appcompat.app.AlertDialog | ||
|
||
|
||
/** | ||
* @author Saksham | ||
* | ||
* @note Last Branch Update - | ||
* @note Created on 2018-10-04 by Saksham | ||
* | ||
* @note Updates : | ||
*/ | ||
object Dialog { | ||
private lateinit var alertDialog: AlertDialog | ||
|
||
// simple ok dialog | ||
fun simpleOk(context: Context, title: String,message: String, positive: DialogInterface.OnClickListener) { | ||
var builder = AlertDialog.Builder(context) | ||
builder | ||
.setTitle(title) | ||
.setMessage(message) | ||
.setPositiveButton("OK", positive) | ||
.setNegativeButton("CANCEL") { dialog, _ -> | ||
dialog.dismiss() | ||
} | ||
.setCancelable(false) | ||
|
||
alertDialog = builder.create() | ||
alertDialog.show() | ||
|
||
} | ||
|
||
// dismiss | ||
fun dismiss(){ | ||
alertDialog.dismiss() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:viewportWidth="24" | ||
android:viewportHeight="24" android:width="24dp" android:height="24dp"> | ||
<path android:fillColor="@color/blue" | ||
android:pathData="M12 4A4 4 0 0 1 16 8A4 4 0 0 1 12 12A4 4 0 0 1 8 8A4 4 0 0 1 12 4M12 14C16.42 14 20 15.79 20 18V20H4V18C4 15.79 7.58 14 12 14Z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:viewportWidth="24" | ||
android:viewportHeight="24" android:width="24dp" android:height="24dp"> | ||
<path android:fillColor="@color/black" | ||
android:pathData="M17 17.25V14H10V10H17V6.75L22.25 12L17 17.25M13 2A2 2 0 0 1 15 4V8H13V4H4V20H13V16H15V20A2 2 0 0 1 13 22H4A2 2 0 0 1 2 20V4A2 2 0 0 1 4 2H13Z" /> | ||
</vector> |
Oops, something went wrong.