Skip to content

Commit

Permalink
Required feedback message (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
anjmao authored Dec 5, 2019
1 parent f03afda commit efc3492
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 27 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ You can install this APK by:
##### Internal release
- Increase bundle_release versionCode + 1 in fastlane/Fastlane file.
- Build and publish internal release:
```bash
source fastlane/.env.local && fastlane android beta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ class FeedbackFragment : Fragment() {
}

private fun handleFeedbackSubmit(root: View) {
if (!feedbackViewModel.isMessageSet()) {
showMessage(root.context, getString(R.string.feedback_message_required))
return
}

feedbackSubmitButton.isEnabled = false
navigateTo(root, Screen.MAIN)
showMessage(root.context, getString(R.string.feedback_submit_success))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class FeedbackViewModel(private val nodeRepository: NodeRepository): ViewModel()
message = msg
}

fun isMessageSet(): Boolean {
return message != ""
}

suspend fun submit() {
val req = SendFeedbackRequest()
req.description = "Platform: Android, Feedback Type: $feebackType, Message: $message"
Expand Down
16 changes: 11 additions & 5 deletions android/app/src/main/java/network/mysterium/ui/MainVpnFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ class MainVpnFragment : Fragment() {
private lateinit var vpnStatsDurationLabel: TextView
private lateinit var vpnStatsBytesSentLabel: TextView
private lateinit var vpnStatsBytesReceivedLabel: TextView
private lateinit var vpnStatsBytesReceivedUnits: TextView
private lateinit var vpnStatsBytesSentUnits: TextView

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
Expand All @@ -80,6 +82,8 @@ class MainVpnFragment : Fragment() {
vpnStatsDurationLabel = root.findViewById(R.id.vpn_stats_duration)
vpnStatsBytesReceivedLabel = root.findViewById(R.id.vpn_stats_bytes_received)
vpnStatsBytesSentLabel = root.findViewById(R.id.vpn_stats_bytes_sent)
vpnStatsBytesReceivedUnits = root.findViewById(R.id.vpn_stats_bytes_received_units)
vpnStatsBytesSentUnits = root.findViewById(R.id.vpn_stats_bytes_sent_units)

feedbackButton.setOnClickListener {
navigateTo(root, Screen.FEEDBACK)
Expand Down Expand Up @@ -137,8 +141,10 @@ class MainVpnFragment : Fragment() {

private fun updateStatsLabels(it: StatisticsViewItem) {
vpnStatsDurationLabel.text = it.duration
vpnStatsBytesReceivedLabel.text = it.bytesReceived
vpnStatsBytesSentLabel.text = it.bytesSent
vpnStatsBytesReceivedLabel.text = it.bytesReceived.value
vpnStatsBytesReceivedUnits.text = it.bytesReceived.units
vpnStatsBytesSentLabel.text = it.bytesSent.value
vpnStatsBytesSentUnits.text = it.bytesSent.units
}

private fun updateConnStateLabel(it: ConnectionState) {
Expand Down Expand Up @@ -212,7 +218,7 @@ class MainVpnFragment : Fragment() {
private fun connect(ctx: Context) {
val proposal: ProposalViewItem? = sharedViewModel.selectedProposal.value
if (proposal == null) {
showMessage(ctx, "Select proposal!")
showMessage(ctx, getString(R.string.vpn_select_proposal_warning))
return
}
job?.cancel()
Expand All @@ -223,7 +229,7 @@ class MainVpnFragment : Fragment() {
} catch (e: kotlinx.coroutines.CancellationException) {
// Do nothing.
} catch (e: Exception) {
showMessage(ctx, "Failed to connect. Please try again.")
showMessage(ctx, getString(R.string.vpn_failed_to_connect))
Log.e(TAG, "Failed to connect", e)
}
}
Expand All @@ -236,7 +242,7 @@ class MainVpnFragment : Fragment() {
try {
sharedViewModel.disconnect()
} catch (e: Exception) {
showMessage(ctx, "Failed to disconnect. Please try again.")
showMessage(ctx, getString(R.string.vpn_failed_to_disconnect))
Log.e(TAG, "Failed to disconnect", e)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ class LocationViewItem(

class StatisticsViewItem(
val duration: String,
val bytesReceived: String,
val bytesSent: String
val bytesReceived: FormattedBytesViewItem,
val bytesSent: FormattedBytesViewItem
) {
companion object {
fun from(it: Statistics): StatisticsViewItem {
Expand Down Expand Up @@ -196,19 +196,17 @@ class SharedViewModel(
// This is needed since status change can be executed on separate
// inside go node library.
viewModelScope.launch {
val s = StatisticsViewItem(
duration = UnitFormatter.timeDisplay(it.duration.toDouble()),
bytesReceived = UnitFormatter.bytesDisplay(it.bytesReceived.toDouble()),
bytesSent = UnitFormatter.bytesDisplay(it.bytesSent.toDouble())
)
statistics.value = s
val s = StatisticsViewItem.from(it)
statistics.value = StatisticsViewItem.from(it)

// Show global notification with connected country and statistics.
// At this point we need to check if proposal is not null since
// statistics event can fire sooner than proposal is loaded.
if (selectedProposal.value != null) {
val countryName = selectedProposal.value?.countryName
mysteriumCoreService.await().showNotification("Connected to $countryName", "Received ${s.bytesReceived} | Send ${s.bytesSent}")
val notificationTitle = "Connected to $countryName"
val notificationContent = "Received ${s.bytesReceived.value} ${s.bytesReceived.units} | Send ${s.bytesSent.value} ${s.bytesSent.units}"
mysteriumCoreService.await().showNotification(notificationTitle, notificationContent)
}
}
}
Expand Down
13 changes: 8 additions & 5 deletions android/app/src/main/java/network/mysterium/ui/UnitFormatter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,20 @@ package network.mysterium.ui
import kotlin.math.floor
import kotlin.math.roundToInt


class FormattedBytesViewItem(val value: String, val units: String)

object UnitFormatter {
val KB = 1024
val MB = 1024 * KB
val GB = 1024 * MB

fun bytesDisplay(bytes: Double): String {
fun bytesDisplay(bytes: Double): FormattedBytesViewItem {
return when {
bytes < KB -> "$bytes B"
bytes < MB -> "%.2f KB".format(bytes / KB)
bytes < GB -> "%.2f MB".format(bytes / MB)
else -> "%.2f GB".format(bytes / GB)
bytes < KB -> FormattedBytesViewItem("$bytes", "B")
bytes < MB -> FormattedBytesViewItem("%.2f".format(bytes / KB), "KB")
bytes < GB -> FormattedBytesViewItem("%.2f".format(bytes / MB), "MB")
else -> FormattedBytesViewItem("%.2f".format(bytes / GB), "GB")
}
}

Expand Down
4 changes: 2 additions & 2 deletions android/app/src/main/res/layout/fragment_main_vpn.xml
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@
android:text="0" />

<TextView
android:id="@+id/textView9"
android:id="@+id/vpn_stats_bytes_received_units"
style="@style/VpnStatsLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -314,7 +314,7 @@
android:text="0" />

<TextView
android:id="@+id/textView14"
android:id="@+id/vpn_stats_bytes_sent_units"
style="@style/VpnStatsLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
4 changes: 4 additions & 0 deletions android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@
<string name="connect_button_loading">Loading</string>
<string name="vpn_status_loading">Loading</string>
<string name="feedback_message_label">Message</string>
<string name="feedback_message_required">Message is required.</string>
<string name="vpn_select_proposal_warning">Please select proposal to connect.</string>
<string name="vpn_failed_to_connect">Failed to connect. Please try again.</string>
<string name="vpn_failed_to_disconnect">Failed to disconnect. Please try again.</string>
</resources>
12 changes: 8 additions & 4 deletions android/app/src/test/java/UnitFormatterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ class UnitFormatterTest {
fun testBytesFormatting() {
var longVal: Long = 101
var res = UnitFormatter.bytesDisplay(longVal.toDouble())
assertEquals("101.0 B", res)
assertEquals("101.0 B", "${res.value} ${res.units}")

longVal = 1028
res = UnitFormatter.bytesDisplay(longVal.toDouble())
assertEquals("1.00 KB", res)
assertEquals("1.00 KB", "${res.value} ${res.units}")

longVal = 81068
res = UnitFormatter.bytesDisplay(longVal.toDouble())
assertEquals("79.17 KB", res)
assertEquals("79.17 KB", "${res.value} ${res.units}")

longVal = 9381068
res = UnitFormatter.bytesDisplay(longVal.toDouble())
assertEquals("8.95 MB", res)
assertEquals("8.95 MB", "${res.value} ${res.units}")

longVal = 1309381068
res = UnitFormatter.bytesDisplay(longVal.toDouble())
assertEquals("1.22 GB", "${res.value} ${res.units}")
}
}
4 changes: 2 additions & 2 deletions fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ platform :android do
project_dir: "android",
print_command: false, # to prevent outputting passwords
properties: {
'versionCode' => 10000 + number_of_commits,
'versionCode' => 1,
'versionName' => last_git_tag,
'applyGoogleServices' => true,
"android.injected.signing.store.file" => ENV["FASTLANE_ANDROID_SIGNING_FILE_PATH"],
Expand All @@ -42,7 +42,7 @@ platform :android do
project_dir: "android",
print_command: false, # to prevent outputting passwords
properties: {
'versionCode' => 10000 + number_of_commits,
'versionCode' => 10694,
'versionName' => last_git_tag,
'applyGoogleServices' => true,
"android.injected.signing.store.file" => ENV["FASTLANE_ANDROID_SIGNING_FILE_PATH"],
Expand Down

0 comments on commit efc3492

Please sign in to comment.