Add licenses activity

This commit is contained in:
Davide Depau 2018-08-30 19:10:48 +02:00
parent c99833f0a6
commit 6a25f7aade
13 changed files with 255 additions and 42 deletions

View file

@ -23,10 +23,16 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<service android:name=".services.UsbApiImgWriteService"
<service
android:name=".services.UsbApiImgWriteService"
android:exported="false"/>
<service android:name=".services.UsbApiDmgWriteService"
<service
android:name=".services.UsbApiDmgWriteService"
android:exported="false"/>
<activity android:name=".activities.LicensesActivity">
</activity>
</application>
</manifest>

View file

@ -0,0 +1,74 @@
package eu.depau.etchdroid.activities
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.MenuItem
import android.view.View
import eu.depau.etchdroid.R
import eu.depau.etchdroid.adapters.LicenseRecyclerViewAdapter
import eu.depau.etchdroid.utils.ClickListener
import eu.depau.etchdroid.utils.License
import eu.depau.etchdroid.utils.RecyclerViewTouchListener
import kotlinx.android.synthetic.main.activity_licenses.*
class LicensesActivity : AppCompatActivity() {
private lateinit var recyclerView: RecyclerView
private lateinit var viewManager: RecyclerView.LayoutManager
private lateinit var viewAdapter: LicenseRecyclerViewAdapter
lateinit var licenses: Array<License>
private fun updateLicenses() {
if (!::licenses.isInitialized) {
licenses = arrayOf(
License(getString(R.string.this_app), Uri.parse("https://github.com/Depau/EtchDroid"), getString(R.string.license_gpl3)),
License("libaums (fork)", Uri.parse("https://github.com/Depau/libaums"), getString(R.string.license_apache2_0), getString(R.string.libaums_license_desc)),
License("dmg2img (fork)", Uri.parse("https://github.com/Depau/dmg2img-cmake"), getString(R.string.license_gpl2), getString(R.string.dmg2img_license_desc)),
License("bzip2", Uri.parse("https://github.com/LuaDist/bzip2/"), getString(R.string.license_bzip2)),
License("LibreSSL", Uri.parse("https://github.com/libressl-portable/portable"), getString(R.string.license_custom))
)
}
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_licenses)
updateLicenses()
title = getString(R.string.licenses)
// Enable back button in action bar
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
viewManager = LinearLayoutManager(this)
recyclerView = licenses_recycler_view
viewAdapter = LicenseRecyclerViewAdapter(licenses)
recyclerView.adapter = viewAdapter
recyclerView.layoutManager = viewManager
recyclerView.addOnItemTouchListener(RecyclerViewTouchListener(this, recyclerView, object : ClickListener {
override fun onClick(view: View, position: Int) {
val intent = Intent(Intent.ACTION_VIEW, viewAdapter.get(position).url)
startActivity(intent)
}
override fun onLongClick(view: View, position: Int) {}
}))
}
override fun onOptionsItemSelected(item: MenuItem?): Boolean {
when (item?.itemId) {
android.R.id.home -> {
finish()
return true
}
}
return super.onOptionsItemSelected(item)
}
}

View file

@ -91,7 +91,11 @@ class MainActivity : WizardActivity() {
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
return when (item.itemId) {
R.id.action_settings -> true
R.id.action_licenses -> {
val intent = Intent(this, LicensesActivity::class.java)
startActivity(intent)
return true
}
else -> super.onOptionsItemSelected(item)
}
}

View file

@ -0,0 +1,43 @@
package eu.depau.etchdroid.adapters
import android.annotation.SuppressLint
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.RelativeLayout
import eu.depau.etchdroid.R
import eu.depau.etchdroid.utils.License
import kotlinx.android.synthetic.main.license_row.view.*
class LicenseRecyclerViewAdapter(private val dataset: Array<License>) : RecyclerView.Adapter<LicenseRecyclerViewAdapter.ViewHolder>() {
class ViewHolder(val relLayout: RelativeLayout) : RecyclerView.ViewHolder(relLayout)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):
ViewHolder {
val relLayout = LayoutInflater.from(parent.context)
.inflate(R.layout.license_row, parent, false) as RelativeLayout
return ViewHolder(relLayout)
}
@SuppressLint("SetTextI18n")
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val license = dataset[position]
holder.relLayout.software_name.text = license.name
holder.relLayout.software_desc.text = license.description
holder.relLayout.software_license.text = license.license
holder.relLayout.software_url.text = license.url.toString()
holder.relLayout.software_desc.visibility = if (license.description == null) View.GONE else View.VISIBLE
}
override fun getItemCount(): Int = dataset.size
fun get(position: Int): License {
return dataset[position]
}
}

View file

@ -30,11 +30,11 @@ class UsbDrivesRecyclerViewAdapter(private val dataset: Array<UsbMassStorageDevi
val usbDevice = dataset[position].usbDevice
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
holder.relLayout.name.text = "${usbDevice.manufacturerName} ${usbDevice.productName}"
holder.relLayout.usbdev_name.text = "${usbDevice.manufacturerName} ${usbDevice.productName}"
holder.relLayout.devpath.text = usbDevice.deviceName
holder.relLayout.vidpid.text = usbDevice.vidpid
} else {
holder.relLayout.name.text = usbDevice.deviceName
holder.relLayout.usbdev_name.text = usbDevice.deviceName
holder.relLayout.devpath.text = usbDevice.vidpid
}
}

View file

@ -18,6 +18,7 @@ import eu.depau.etchdroid.adapters.UsbDrivesRecyclerViewAdapter
import eu.depau.etchdroid.kotlin_exts.name
import eu.depau.etchdroid.kotlin_exts.snackbar
import eu.depau.etchdroid.enums.WizardStep
import eu.depau.etchdroid.utils.RecyclerViewTouchListener
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_select_usb_drive.view.*
@ -34,37 +35,6 @@ class UsbDriveFragment : WizardFragment(), SwipeRefreshLayout.OnRefreshListener
private lateinit var refreshLayout: SwipeRefreshLayout
class RecyclerViewTouchListener(context: Context, val recyclerView: RecyclerView, val clickListener: ClickListener) : RecyclerView.OnItemTouchListener {
private var gestureDetector: GestureDetector
init {
gestureDetector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapUp(e: MotionEvent): Boolean {
return true
}
override fun onLongPress(e: MotionEvent) {
val child = recyclerView.findChildViewUnder(e.x, e.y)
if (child != null)
clickListener.onLongClick(child, recyclerView.getChildAdapterPosition(child))
}
})
}
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
val child = rv.findChildViewUnder(e.x, e.y)
if (child != null && gestureDetector.onTouchEvent(e)) {
clickListener.onClick(child, rv.getChildAdapterPosition(child))
}
return false
}
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}
}
override fun onRefresh() {
loadUsbDevices()
}

View file

@ -0,0 +1,10 @@
package eu.depau.etchdroid.utils
import android.net.Uri
data class License(
val name: String,
val url: Uri,
val license: String,
val description: String? = null
)

View file

@ -0,0 +1,36 @@
package eu.depau.etchdroid.utils
import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.GestureDetector
import android.view.MotionEvent
class RecyclerViewTouchListener(context: Context, val recyclerView: RecyclerView, val clickListener: ClickListener) : RecyclerView.OnItemTouchListener {
private var gestureDetector: GestureDetector
init {
gestureDetector = GestureDetector(context, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapUp(e: MotionEvent): Boolean {
return true
}
override fun onLongPress(e: MotionEvent) {
val child = recyclerView.findChildViewUnder(e.x, e.y)
if (child != null)
clickListener.onLongClick(child, recyclerView.getChildAdapterPosition(child))
}
})
}
override fun onTouchEvent(rv: RecyclerView, e: MotionEvent) {}
override fun onInterceptTouchEvent(rv: RecyclerView, e: MotionEvent): Boolean {
val child = rv.findChildViewUnder(e.x, e.y)
if (child != null && gestureDetector.onTouchEvent(e)) {
clickListener.onClick(child, rv.getChildAdapterPosition(child))
}
return false
}
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}
}

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.LicensesActivity">
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/licenses_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</android.support.constraint.ConstraintLayout>

View file

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:paddingBottom="@dimen/row_padding"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/row_padding">
<TextView
android:id="@+id/software_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:ellipsize="end"
android:textColor="@color/name"
android:textSize="16sp"
android:textStyle="bold"/>
<TextView
android:id="@+id/software_desc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/software_name"/>
<TextView
android:id="@+id/software_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/software_desc"/>
<TextView
android:id="@+id/software_license"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:textColor="@color/info"/>
</RelativeLayout>

View file

@ -12,7 +12,7 @@
android:paddingTop="@dimen/row_padding">
<TextView
android:id="@+id/name"
android:id="@+id/usbdev_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
@ -25,7 +25,7 @@
android:id="@+id/devpath"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/name"/>
android:layout_below="@id/usbdev_name"/>
<TextView
android:id="@+id/vidpid"

View file

@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
tools:context="eu.depau.etchdroid.activities.MainActivity">
<item
android:id="@+id/action_settings"
android:id="@+id/action_licenses"
android:orderInCategory="100"
android:title="@string/action_settings"
android:title="@string/licenses"
app:showAsAction="never"/>
</menu>

View file

@ -72,4 +72,13 @@
<string name="fs_type">Type</string>
<string name="part_size">Size</string>
<string name="no_image_size_check_dmg">Image size checks can\'t be performed on DMG images. Make sure the USB drive is large enough before flashing.</string>
<string name="license_gpl3">GNU GPLv3</string>
<string name="this_app">This app</string>
<string name="license_apache2_0">Apache 2.0</string>
<string name="libaums_license_desc">Userspace USB block device implementation</string>
<string name="license_gpl2">GNU GPLv2</string>
<string name="license_bzip2">Custom BSD-like</string>
<string name="license_custom">Custom</string>
<string name="licenses">Licenses</string>
<string name="dmg2img_license_desc">Converts compressed Apple® DMG images</string>
</resources>