mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +05:30
Login/Register Dialog
This commit is contained in:
parent
9607fd5c30
commit
27e7d56340
@ -19,8 +19,6 @@ import java.io.IOException
|
||||
|
||||
class Home : Fragment() {
|
||||
|
||||
private var param1: String? = null
|
||||
private var param2: String? = null
|
||||
private val TAG = "HomeFragment"
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
104
app/src/main/java/com/github/libretube/LoginDialog.kt
Normal file
104
app/src/main/java/com/github/libretube/LoginDialog.kt
Normal file
@ -0,0 +1,104 @@
|
||||
package com.github.libretube
|
||||
|
||||
import android.app.Dialog
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.github.libretube.adapters.TrendingAdapter
|
||||
import com.github.libretube.obj.Login
|
||||
import retrofit2.HttpException
|
||||
import java.io.IOException
|
||||
import java.lang.Exception
|
||||
import kotlin.math.log
|
||||
|
||||
class LoginDialog : DialogFragment() {
|
||||
private val TAG = "LoginDialog"
|
||||
lateinit var username: EditText
|
||||
lateinit var password: EditText
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
return activity?.let {
|
||||
val builder = AlertDialog.Builder(it)
|
||||
// Get the layout inflater
|
||||
val inflater = requireActivity().layoutInflater;
|
||||
|
||||
// Inflate and set the layout for the dialog
|
||||
// Pass null as the parent view because its going in the dialog layout
|
||||
val view = inflater.inflate(R.layout.dialog_login, null)
|
||||
username=view.findViewById(R.id.username)
|
||||
password=view.findViewById(R.id.password)
|
||||
view.findViewById<Button>(R.id.login).setOnClickListener {
|
||||
val login = Login(username.text.toString(),password.text.toString())
|
||||
login(login)
|
||||
}
|
||||
view.findViewById<Button>(R.id.register).setOnClickListener {
|
||||
val login = Login(username.text.toString(),password.text.toString())
|
||||
register(login)
|
||||
}
|
||||
builder.setView(view)
|
||||
// Add action buttons
|
||||
builder.create()
|
||||
} ?: throw IllegalStateException("Activity cannot be null")
|
||||
}
|
||||
private fun login(login: Login){
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.login(login)
|
||||
}catch(e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response")
|
||||
return@launchWhenCreated
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG,"dafaq?"+e.toString())
|
||||
return@launchWhenCreated
|
||||
}
|
||||
if (response.error!= null){
|
||||
Toast.makeText(context, response.error, Toast.LENGTH_SHORT).show()
|
||||
}else{
|
||||
Toast.makeText(context,R.string.loggedIn, Toast.LENGTH_SHORT).show()
|
||||
dialog?.dismiss()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
private fun register(login: Login){
|
||||
fun run() {
|
||||
lifecycleScope.launchWhenCreated {
|
||||
val response = try {
|
||||
RetrofitInstance.api.register(login)
|
||||
}catch(e: IOException) {
|
||||
println(e)
|
||||
Log.e(TAG, "IOException, you might not have internet connection")
|
||||
return@launchWhenCreated
|
||||
} catch (e: HttpException) {
|
||||
Log.e(TAG, "HttpException, unexpected response")
|
||||
return@launchWhenCreated
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG,"dafaq?"+e.toString())
|
||||
return@launchWhenCreated
|
||||
}
|
||||
if (response.error!= null){
|
||||
Toast.makeText(context, response.error, Toast.LENGTH_SHORT).show()
|
||||
}else{
|
||||
Toast.makeText(context,R.string.registered, Toast.LENGTH_SHORT).show()
|
||||
dialog?.dismiss()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
run()
|
||||
}
|
||||
|
||||
}
|
@ -229,8 +229,6 @@ class PlayerFragment : Fragment() {
|
||||
|
||||
override fun onStop() {
|
||||
super.onStop()
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
|
@ -1,10 +1,12 @@
|
||||
package com.github.libretube
|
||||
|
||||
import android.media.Image
|
||||
import android.os.Bundle
|
||||
import androidx.fragment.app.Fragment
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
|
||||
// TODO: Rename parameter arguments, choose names that match
|
||||
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||
@ -37,6 +39,15 @@ class Subscriptions : Fragment() {
|
||||
return inflater.inflate(R.layout.fragment_subscriptions, container, false)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
view.findViewById<ImageView>(R.id.boogh).setOnClickListener {
|
||||
val newFragment = LoginDialog()
|
||||
newFragment.show(childFragmentManager,"fuck")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Use this factory method to create a new instance of
|
||||
|
54
app/src/main/res/layout/dialog_login.xml
Normal file
54
app/src/main/res/layout/dialog_login.xml
Normal file
@ -0,0 +1,54 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<ImageView
|
||||
android:src="@drawable/ic_libretube_foreground"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:scaleType="center"
|
||||
android:background="#CD5757"
|
||||
android:contentDescription="@string/app_name" />
|
||||
<EditText
|
||||
android:id="@+id/username"
|
||||
android:inputType="textShortMessage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_marginBottom="4dp"
|
||||
android:hint="@string/username" />
|
||||
<EditText
|
||||
android:id="@+id/password"
|
||||
android:inputType="textPassword"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:fontFamily="sans-serif"
|
||||
android:hint="@string/password"/>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center">
|
||||
<Button
|
||||
android:id="@+id/login"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/login"
|
||||
android:padding="8dp"
|
||||
android:layout_margin="8dp"/>
|
||||
<Button
|
||||
android:id="@+id/register"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/register"
|
||||
android:padding="8dp"
|
||||
android:layout_margin="8dp"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
@ -14,7 +14,7 @@
|
||||
>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/player_like"
|
||||
android:id="@+id/boogh"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_centerInParent="true"
|
||||
@ -25,7 +25,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Coming Soon!"
|
||||
android:id="@+id/textLike"
|
||||
android:layout_below="@id/player_like"
|
||||
android:layout_below="@id/boogh"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:textStyle="bold"
|
||||
android:textSize="20sp"
|
||||
|
@ -8,4 +8,11 @@
|
||||
<string name="share">Share</string>
|
||||
<string name="download">Download</string>
|
||||
<string name="save">Save</string>
|
||||
<string name="username">Username</string>
|
||||
<string name="password">Password</string>
|
||||
<string name="login">Login</string>
|
||||
<string name="register">Register</string>
|
||||
<string name="cancel">Cancel</string>
|
||||
<string name="loggedIn">Logged in successfully!</string>
|
||||
<string name="registered">Registered successfully! You may now subscribe to channels you want.</string>
|
||||
</resources>
|
Loading…
x
Reference in New Issue
Block a user