This commit is contained in:
Niels Andriesse
2019-08-23 13:22:52 +10:00
parent 5d34314a00
commit d831274920
9 changed files with 47 additions and 88 deletions

View File

@@ -71,11 +71,11 @@ public class DeviceActivity extends PassphraseRequiredActionBarActivity
this.deviceListFragment.setAddDeviceButtonListener(this);
this.deviceAddFragment.setScanListener(this);
if (getIntent().getBooleanExtra("add", false)) {
// if (getIntent().getBooleanExtra("add", false)) {
initFragment(android.R.id.content, deviceAddFragment, dynamicLanguage.getCurrentLocale());
} else {
initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.getCurrentLocale());
}
// } else {
// initFragment(android.R.id.content, deviceListFragment, dynamicLanguage.getCurrentLocale());
// }
}
@Override

View File

@@ -53,7 +53,7 @@ public class NewConversationActivity extends ContactSelectionActivity {
boolean isValid = PublicKeyValidation.isValid(number);
if (!isValid) {
Toast.makeText(this, R.string.activity_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.fragment_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show();
return;
}

View File

@@ -25,7 +25,7 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity(), ScanListe
}
override fun onCreate(bundle: Bundle?, isReady: Boolean) {
supportActionBar!!.setTitle(R.string.activity_new_conversation_title)
supportActionBar!!.setTitle(R.string.fragment_new_conversation_title)
supportActionBar!!.setDisplayHomeAsUpEnabled(true)
val fragment = NewConversationFragment()
initFragment(android.R.id.content, fragment, null)
@@ -51,7 +51,7 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity(), ScanListe
.withPermanentDenialDialog(getString(R.string.fragment_qr_code_camera_permission_dialog_message))
.onAllGranted {
val fragment = ScanQRCodeFragment()
fragment.setScanListener(this)
fragment.scanListener = this
supportFragmentManager.beginTransaction().replace(android.R.id.content, fragment).addToBackStack(null).commitAllowingStateLoss()
}
.onAnyDenied { Toast.makeText(this, R.string.fragment_qr_code_camera_permission_denied_message, Toast.LENGTH_SHORT).show() }
@@ -75,7 +75,7 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity(), ScanListe
startActivity(intent)
finish()
} else {
Toast.makeText(this, R.string.activity_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show()
Toast.makeText(this, R.string.fragment_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show()
}
}
}

View File

@@ -5,13 +5,13 @@ import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.activity_new_conversation.*
import kotlinx.android.synthetic.main.fragment_new_conversation.*
import network.loki.messenger.R
class NewConversationFragment() : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.activity_new_conversation, container, false)
return inflater.inflate(R.layout.fragment_new_conversation, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
@@ -30,6 +30,6 @@ class NewConversationFragment() : Fragment() {
override fun onResume() {
super.onResume()
val activity = activity as NewConversationActivity
activity.supportActionBar!!.setTitle(R.string.activity_new_conversation_title)
activity.supportActionBar!!.setTitle(R.string.fragment_new_conversation_title)
}
}

View File

@@ -1,98 +1,58 @@
package org.thoughtcrime.securesms.loki
import android.annotation.TargetApi
import android.content.res.Configuration
import android.os.Build
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewAnimationUtils
import android.view.ViewGroup
import android.view.animation.DecelerateInterpolator
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.fragment_scan_qr_code.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.components.camera.CameraView
import org.thoughtcrime.securesms.qr.ScanListener
import org.thoughtcrime.securesms.qr.ScanningThread
import org.thoughtcrime.securesms.util.ViewUtil
class ScanQRCodeFragment : Fragment() {
private val scanningThread = ScanningThread()
var scanListener: ScanListener? = null
set(value) { field = value; scanningThread.setScanListener(scanListener) }
private var container: ViewGroup? = null
private var overlay: LinearLayout? = null
private var scannerView: CameraView? = null
private var scanningThread: ScanningThread? = null
private var scanListener: ScanListener? = null
override fun onCreateView(layoutInflater: LayoutInflater, viewGroup: ViewGroup?, bundle: Bundle?): View? {
return layoutInflater.inflate(R.layout.fragment_scan_qr_code, viewGroup, false)
}
override fun onCreateView(inflater: LayoutInflater, viewGroup: ViewGroup?, bundle: Bundle?): View? {
this.container = ViewUtil.inflate(inflater, viewGroup!!, R.layout.fragment_scan_qr_code)
this.overlay = ViewUtil.findById(this.container!!, R.id.overlay)
this.scannerView = ViewUtil.findById(this.container!!, R.id.cameraView)
if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
this.overlay!!.orientation = LinearLayout.HORIZONTAL
} else {
this.overlay!!.orientation = LinearLayout.VERTICAL
override fun onViewCreated(view: View, bundle: Bundle?) {
super.onViewCreated(view, bundle)
when (resources.configuration.orientation) {
Configuration.ORIENTATION_LANDSCAPE -> overlayView.orientation = LinearLayout.HORIZONTAL
else -> overlayView.orientation = LinearLayout.VERTICAL
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
this.container!!.addOnLayoutChangeListener(object : View.OnLayoutChangeListener {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
override fun onLayoutChange(v: View, left: Int, top: Int, right: Int, bottom: Int,
oldLeft: Int, oldTop: Int, oldRight: Int, oldBottom: Int) {
v.removeOnLayoutChangeListener(this)
val reveal = ViewAnimationUtils.createCircularReveal(v, right, bottom, 0f, Math.hypot(right.toDouble(), bottom.toDouble()).toInt().toFloat())
reveal.interpolator = DecelerateInterpolator(2f)
reveal.duration = 800
reveal.start()
}
})
}
return this.container
}
override fun onResume() {
super.onResume()
this.scanningThread = ScanningThread()
this.scanningThread!!.setScanListener(scanListener)
this.scannerView!!.onResume()
this.scannerView!!.setPreviewCallback(scanningThread!!)
this.scanningThread!!.start()
this.scanningThread.setScanListener(scanListener)
this.cameraView.onResume()
this.cameraView.setPreviewCallback(scanningThread)
this.scanningThread.start()
val activity = activity as NewConversationActivity
activity.supportActionBar!!.setTitle(R.string.fragment_scan_qr_code_title)
}
override fun onPause() {
super.onPause()
this.scannerView!!.onPause()
this.scanningThread!!.stopScanning()
this.cameraView.onPause()
this.scanningThread.stopScanning()
}
override fun onConfigurationChanged(newConfiguration: Configuration?) {
override fun onConfigurationChanged(newConfiguration: Configuration) {
super.onConfigurationChanged(newConfiguration)
this.scannerView!!.onPause()
if (newConfiguration!!.orientation == Configuration.ORIENTATION_LANDSCAPE) {
overlay!!.orientation = LinearLayout.HORIZONTAL
} else {
overlay!!.orientation = LinearLayout.VERTICAL
this.cameraView.onPause()
when (newConfiguration.orientation) {
Configuration.ORIENTATION_LANDSCAPE -> overlayView.orientation = LinearLayout.HORIZONTAL
else -> overlayView.orientation = LinearLayout.VERTICAL
}
this.scannerView!!.onResume()
this.scannerView!!.setPreviewCallback(scanningThread!!)
cameraView.onResume()
cameraView.setPreviewCallback(scanningThread)
}
fun setScanListener(scanListener: ScanListener) {
this.scanListener = scanListener
if (this.scanningThread != null) {
this.scanningThread!!.setScanListener(scanListener)
}
}
}