general fixes

This commit is contained in:
rimthekid 2022-03-18 08:13:07 -07:00
parent 9726d55ec4
commit adad574c18
13 changed files with 123 additions and 59 deletions

View File

@ -2,57 +2,30 @@ package com.github.libretube
import android.content.Context import android.content.Context
import android.util.AttributeSet import android.util.AttributeSet
import android.view.KeyEvent.ACTION_DOWN
import android.view.KeyEvent.ACTION_UP
import android.view.MotionEvent import android.view.MotionEvent
import android.view.MotionEvent.ACTION_CANCEL
import android.view.MotionEvent.ACTION_MOVE import android.view.MotionEvent.ACTION_MOVE
import android.view.View
import android.view.ViewConfiguration import android.view.ViewConfiguration
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import kotlin.math.abs
class CustomSwipeToRefresh
@JvmOverloads
constructor(
context: Context,
attrs: AttributeSet? = null
) : SwipeRefreshLayout(context, attrs) {
private val touchSlop: Int = ViewConfiguration.get(context).scaledTouchSlop
private var startX = 0f
private var startY = 0f
private var forbidSwipe = false
private var isStartScrolledByY = false
class CustomSwipeToRefresh(context: Context?, attrs: AttributeSet?) :
SwipeRefreshLayout(context!!, attrs) {
private val mTouchSlop: Int
private var mPrevX = 0f
override fun onInterceptTouchEvent(event: MotionEvent): Boolean { override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
when (event.action) { when (event.action) {
ACTION_DOWN -> { MotionEvent.ACTION_DOWN -> mPrevX = MotionEvent.obtain(event).x
startX = event.x
startY = event.y
}
ACTION_MOVE -> { ACTION_MOVE -> {
val isScrolledByX = abs(event.x - startX) > touchSlop val eventX = event.x
val isScrolledByY = abs(event.y - startY) > touchSlop val xDiff = Math.abs(eventX - mPrevX)
if (!forbidSwipe && isScrolledByY) { if (xDiff > mTouchSlop) {
isStartScrolledByY = true
}
if ((isScrolledByX || forbidSwipe) && !isStartScrolledByY) {
forbidSwipe = true
return false return false
} }
} }
ACTION_CANCEL, ACTION_UP -> {
forbidSwipe = false
isStartScrolledByY = false
}
} }
return super.onInterceptTouchEvent(event) return super.onInterceptTouchEvent(event)
} }
override fun onNestedScroll(target: View, dxConsumed: Int, dyConsumed: Int, dxUnconsumed: Int, dyUnconsumed: Int) { init {
if (forbidSwipe) return mTouchSlop = ViewConfiguration.get(context).scaledTouchSlop
super.onNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed)
} }
} }

View File

@ -7,10 +7,12 @@ import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.ProgressBar import android.widget.ProgressBar
import android.widget.Toast
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import okhttp3.* import okhttp3.*
import retrofit2.HttpException import retrofit2.HttpException
@ -21,6 +23,7 @@ import java.io.IOException
class Home : Fragment() { class Home : Fragment() {
private val TAG = "HomeFragment" private val TAG = "HomeFragment"
private var refreshLayout: SwipeRefreshLayout? = null
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
arguments?.let { arguments?.let {
@ -43,6 +46,13 @@ class Home : Fragment() {
recyclerView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items)) recyclerView.layoutManager = GridLayoutManager(view.context, resources.getInteger(R.integer.grid_items))
val progressbar = view.findViewById<ProgressBar>(R.id.progressBar) val progressbar = view.findViewById<ProgressBar>(R.id.progressBar)
fetchJson(progressbar,recyclerView) fetchJson(progressbar,recyclerView)
refreshLayout = view.findViewById(R.id.home_refresh)
refreshLayout?.isEnabled = true
refreshLayout?.setOnRefreshListener {
Log.d(TAG,"hmm")
fetchJson(progressbar,recyclerView)
}
} }
@ -57,10 +67,14 @@ class Home : Fragment() {
}catch(e: IOException) { }catch(e: IOException) {
println(e) println(e)
Log.e(TAG, "IOException, you might not have internet connection") Log.e(TAG, "IOException, you might not have internet connection")
Toast.makeText(context,R.string.unknown_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated return@launchWhenCreated
} catch (e: HttpException) { } catch (e: HttpException) {
Log.e(TAG, "HttpException, unexpected response") Log.e(TAG, "HttpException, unexpected response")
Toast.makeText(context,R.string.server_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated return@launchWhenCreated
}finally {
refreshLayout?.isRefreshing = false
} }
runOnUiThread { runOnUiThread {
progressBar.visibility = View.GONE progressBar.visibility = View.GONE
@ -79,6 +93,7 @@ class Home : Fragment() {
override fun onDestroyView() { override fun onDestroyView() {
view?.findViewById<RecyclerView>(R.id.recview)?.adapter=null view?.findViewById<RecyclerView>(R.id.recview)?.adapter=null
refreshLayout = null
Log.e(TAG,"destroyview") Log.e(TAG,"destroyview")
super.onDestroyView() super.onDestroyView()
} }

View File

@ -49,12 +49,20 @@ class LoginDialog : DialogFragment() {
username=view.findViewById(R.id.username) username=view.findViewById(R.id.username)
password=view.findViewById(R.id.password) password=view.findViewById(R.id.password)
view.findViewById<Button>(R.id.login).setOnClickListener { view.findViewById<Button>(R.id.login).setOnClickListener {
if(username.text.toString()!="" && password.text.toString()!=""){
val login = Login(username.text.toString(),password.text.toString()) val login = Login(username.text.toString(),password.text.toString())
login(login) login(login)
}else{
Toast.makeText(context,R.string.empty, Toast.LENGTH_SHORT).show()
}
} }
view.findViewById<Button>(R.id.register).setOnClickListener { view.findViewById<Button>(R.id.register).setOnClickListener {
if(username.text.toString()!="" && password.text.toString()!=""){
val login = Login(username.text.toString(),password.text.toString()) val login = Login(username.text.toString(),password.text.toString())
register(login) register(login)
}else{
Toast.makeText(context,R.string.empty, Toast.LENGTH_SHORT).show()
}
} }
} }
builder.setView(view) builder.setView(view)
@ -69,9 +77,11 @@ class LoginDialog : DialogFragment() {
}catch(e: IOException) { }catch(e: IOException) {
println(e) println(e)
Log.e(TAG, "IOException, you might not have internet connection") Log.e(TAG, "IOException, you might not have internet connection")
Toast.makeText(context,R.string.unknown_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated return@launchWhenCreated
} catch (e: HttpException) { } catch (e: HttpException) {
Log.e(TAG, "HttpException, unexpected response") Log.e(TAG, "HttpException, unexpected response")
Toast.makeText(context,R.string.server_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated return@launchWhenCreated
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG,"dafaq?"+e.toString()) Log.e(TAG,"dafaq?"+e.toString())
@ -101,9 +111,11 @@ class LoginDialog : DialogFragment() {
}catch(e: IOException) { }catch(e: IOException) {
println(e) println(e)
Log.e(TAG, "IOException, you might not have internet connection") Log.e(TAG, "IOException, you might not have internet connection")
Toast.makeText(context,R.string.unknown_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated return@launchWhenCreated
} catch (e: HttpException) { } catch (e: HttpException) {
Log.e(TAG, "HttpException, unexpected response") Log.e(TAG, "HttpException, unexpected response")
Toast.makeText(context,R.string.server_error, Toast.LENGTH_SHORT).show()
return@launchWhenCreated return@launchWhenCreated
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG,"dafaq?"+e.toString()) Log.e(TAG,"dafaq?"+e.toString())

View File

@ -181,6 +181,23 @@ class MainActivity : AppCompatActivity() {
motionLayout.transitionToStart() motionLayout.transitionToStart()
}, 100) }, 100)
}else{
var watch = data.path!!.replace("/","")
var bundle = Bundle()
bundle.putString("videoId",watch)
var frag = PlayerFragment()
frag.arguments = bundle
supportFragmentManager.beginTransaction()
.remove(PlayerFragment())
.commit()
supportFragmentManager.beginTransaction()
.replace(R.id.container, frag)
.commitNow()
Handler().postDelayed({
val motionLayout = findViewById<MotionLayout>(R.id.playerMotionLayout)
motionLayout.transitionToEnd()
motionLayout.transitionToStart()
}, 100)
} }
} }

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M9,3L5,6.99h3L8,14h2L10,6.99h3L9,3zM16,17.01L16,10h-2v7.01h-3L15,21l4,-3.99h-3z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z"/>
</vector>

View File

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M14.17,13.71l1.4,-2.42c0.09,-0.15 0.05,-0.34 -0.08,-0.45l-1.48,-1.16c0.03,-0.22 0.05,-0.45 0.05,-0.68s-0.02,-0.46 -0.05,-0.69l1.48,-1.16c0.13,-0.11 0.17,-0.3 0.08,-0.45l-1.4,-2.42c-0.09,-0.15 -0.27,-0.21 -0.43,-0.15L12,4.83c-0.36,-0.28 -0.75,-0.51 -1.18,-0.69l-0.26,-1.85C10.53,2.13 10.38,2 10.21,2h-2.8C7.24,2 7.09,2.13 7.06,2.3L6.8,4.15C6.38,4.33 5.98,4.56 5.62,4.84l-1.74,-0.7c-0.16,-0.06 -0.34,0 -0.43,0.15l-1.4,2.42C1.96,6.86 2,7.05 2.13,7.16l1.48,1.16C3.58,8.54 3.56,8.77 3.56,9s0.02,0.46 0.05,0.69l-1.48,1.16C2,10.96 1.96,11.15 2.05,11.3l1.4,2.42c0.09,0.15 0.27,0.21 0.43,0.15l1.74,-0.7c0.36,0.28 0.75,0.51 1.18,0.69l0.26,1.85C7.09,15.87 7.24,16 7.41,16h2.8c0.17,0 0.32,-0.13 0.35,-0.3l0.26,-1.85c0.42,-0.18 0.82,-0.41 1.18,-0.69l1.74,0.7C13.9,13.92 14.08,13.86 14.17,13.71zM8.81,11c-1.1,0 -2,-0.9 -2,-2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2C10.81,10.1 9.91,11 8.81,11z"/>
<path
android:fillColor="@android:color/white"
android:pathData="M21.92,18.67l-0.96,-0.74c0.02,-0.14 0.04,-0.29 0.04,-0.44c0,-0.15 -0.01,-0.3 -0.04,-0.44l0.95,-0.74c0.08,-0.07 0.11,-0.19 0.05,-0.29l-0.9,-1.55c-0.05,-0.1 -0.17,-0.13 -0.28,-0.1l-1.11,0.45c-0.23,-0.18 -0.48,-0.33 -0.76,-0.44l-0.17,-1.18C18.73,13.08 18.63,13 18.53,13h-1.79c-0.11,0 -0.21,0.08 -0.22,0.19l-0.17,1.18c-0.27,0.12 -0.53,0.26 -0.76,0.44l-1.11,-0.45c-0.1,-0.04 -0.22,0 -0.28,0.1l-0.9,1.55c-0.05,0.1 -0.04,0.22 0.05,0.29l0.95,0.74c-0.02,0.14 -0.03,0.29 -0.03,0.44c0,0.15 0.01,0.3 0.03,0.44l-0.95,0.74c-0.08,0.07 -0.11,0.19 -0.05,0.29l0.9,1.55c0.05,0.1 0.17,0.13 0.28,0.1l1.11,-0.45c0.23,0.18 0.48,0.33 0.76,0.44l0.17,1.18c0.02,0.11 0.11,0.19 0.22,0.19h1.79c0.11,0 0.21,-0.08 0.22,-0.19l0.17,-1.18c0.27,-0.12 0.53,-0.26 0.75,-0.44l1.12,0.45c0.1,0.04 0.22,0 0.28,-0.1l0.9,-1.55C22.03,18.86 22,18.74 21.92,18.67zM17.63,18.83c-0.74,0 -1.35,-0.6 -1.35,-1.35s0.6,-1.35 1.35,-1.35s1.35,0.6 1.35,1.35S18.37,18.83 17.63,18.83z"/>
</vector>

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20,15.31L23.31,12 20,8.69V4h-4.69L12,0.69 8.69,4H4v4.69L0.69,12 4,15.31V20h4.69L12,23.31 15.31,20H20v-4.69zM12,18c-3.31,0 -6,-2.69 -6,-6s2.69,-6 6,-6 6,2.69 6,6 -2.69,6 -6,6z"/>
</vector>

View File

@ -61,13 +61,6 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
android:gravity="center"> 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 <Button
android:id="@+id/register" android:id="@+id/register"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -75,6 +68,14 @@
android:text="@string/register" android:text="@string/register"
android:padding="8dp" android:padding="8dp"
android:layout_margin="8dp"/> android:layout_margin="8dp"/>
<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"/>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

View File

@ -164,9 +164,9 @@
<View android:id="@id/exo_progress_placeholder" <View android:id="@id/exo_progress_placeholder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/exo_styled_progress_layout_height" android:layout_height="15dp"
android:layout_gravity="bottom" android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/exo_styled_progress_margin_bottom" android:layout_marginBottom="1dp"
android:background="@color/exo_bottom_bar_background" android:background="@color/exo_bottom_bar_background"
/> />

View File

@ -15,7 +15,10 @@
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
/> />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/home_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recview" android:id="@+id/recview"
android:layout_width="0dp" android:layout_width="0dp"
@ -25,5 +28,5 @@
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/progressBar" app:layout_constraintTop_toBottomOf="@+id/progressBar"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -31,5 +31,8 @@
<string name="vlcerror">Can\'t open in VLC. Maybe it\'s not installed yet?</string> <string name="vlcerror">Can\'t open in VLC. Maybe it\'s not installed yet?</string>
<string name="import_from_yt">Import subscriptions from youtube</string> <string name="import_from_yt">Import subscriptions from youtube</string>
<string name="app_theme">App theme</string> <string name="app_theme">App theme</string>
<string name="server_error">Server countered a problem. Maybe try another instance?</string>
<string name="unknown_error">Network error!</string>
<string name="empty">Username and Password can\'t be empty!</string>
<string name="notgmail">This is not your gmail account!</string>
</resources> </resources>

View File

@ -13,6 +13,7 @@
app:entryValues="@array/regionsValue" app:entryValues="@array/regionsValue"
app:defaultValue="US" app:defaultValue="US"
app:useSimpleSummaryProvider="true" app:useSimpleSummaryProvider="true"
android:icon="@drawable/ic_language"
/> />
<ListPreference <ListPreference
@ -21,6 +22,7 @@
app:entries="@array/instances" app:entries="@array/instances"
app:entryValues="@array/instancesValue" app:entryValues="@array/instancesValue"
app:defaultValue="https://pipedapi.kavin.rocks/" app:defaultValue="https://pipedapi.kavin.rocks/"
android:icon="@drawable/ic_server"
/> />
<androidx.preference.EditTextPreference <androidx.preference.EditTextPreference
app:key="customInstance" app:key="customInstance"
@ -29,29 +31,24 @@
<androidx.preference.Preference <androidx.preference.Preference
app:key="login_register" app:key="login_register"
app:title="@string/login_register" app:title="@string/login_register"
android:icon="@drawable/ic_login"
android:summary="@string/notgmail"
/> />
<androidx.preference.Preference <androidx.preference.Preference
app:key="import_from_yt" app:key="import_from_yt"
app:title="@string/import_from_yt" app:title="@string/import_from_yt"
android:hint="This is my hint" android:hint="This is my hint"
android:summary=""
android:icon="@drawable/ic_import"
/> />
<!-- <ListPreference-->
<!-- app:key="theme_toggleee"-->
<!-- app:title="@string/region"-->
<!-- app:entries="@array/regions"-->
<!-- app:entryValues="@array/regionsValue"-->
<!-- app:defaultValue="US"-->
<!-- app:useSimpleSummaryProvider="true"-->
<!-- />-->
<ListPreference <ListPreference
app:title="@string/app_theme" app:title="@string/app_theme"
app:key="theme_togglee" app:key="theme_togglee"
app:entries="@array/themes" app:entries="@array/themes"
app:entryValues="@array/themesValue" app:entryValues="@array/themesValue"
app:defaultValue="A" app:defaultValue="A"
android:icon="@drawable/ic_theme"
/> />