Skip to content

Commit

Permalink
リファクタ
Browse files Browse the repository at this point in the history
  • Loading branch information
tateisu committed Sep 10, 2018
1 parent 8160ac2 commit c05eae4
Show file tree
Hide file tree
Showing 22 changed files with 136 additions and 120 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="AllowBackup,GoogleAppIndexingWarning"
android:fullBackupContent="@xml/backup_descriptor"
>

<service
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/jp/juggler/fadownloader/ActMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,6 @@ open class ActMain : AppCompatActivity(), View.OnClickListener {
if(TAB_RECORD == sv) pager.currentItem = page_idx_record
}

override fun onCreateOptionsMenu(menu : Menu) : Boolean {
menuInflater.inflate(R.menu.act_main, menu)
return true
}

private fun permission_request() {
val missing_permission_list = PermissionChecker.getMissingPermissionList(this)
if(! missing_permission_list.isEmpty()) {
Expand Down
30 changes: 13 additions & 17 deletions app/src/main/java/jp/juggler/fadownloader/DownloadWorker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,19 @@ class DownloadWorker : WorkerBase {
get() {
val fc = queued_file_count.get()
val s = _status.get()
if(fc > 0L) {
val bc = queued_byte_count.get()
val bcm = queued_byte_count_max.get()
return s !! + String.format(
"\n%s %d%%, %s %dfile %sbyte",
service.getString(R.string.progress),
if(bcm <= 0) 0 else 100L * (bcm - bc) / bcm,
service.getString(R.string.remain),
fc,
Utils.formatBytes(bc)
)
} else if(s != null && s.contains(MACRO_WAIT_UNTIL)) {
var remain = wait_until.get() - SystemClock.elapsedRealtime()
if(remain < 0L) remain = 0L
return s.replace(MACRO_WAIT_UNTIL, Utils.formatTimeDuration(remain))
} else {
return s
return when {
fc > 0L -> {
val bc = queued_byte_count.get()
val bcm = queued_byte_count_max.get()
"$s\n${service.getString(R.string.progress)} ${if(bcm <= 0) 0 else 100L * (bcm - bc) / bcm}%, ${service.getString(R.string.remain)} ${fc}file ${Utils.formatBytes(bc)}byte"

}
s?.contains(MACRO_WAIT_UNTIL) ==true -> {
var remain = wait_until.get() - SystemClock.elapsedRealtime()
if(remain < 0L) remain = 0L
s.replace(MACRO_WAIT_UNTIL, Utils.formatTimeDuration(remain))
}
else -> s
}
}

Expand Down
16 changes: 7 additions & 9 deletions app/src/main/java/jp/juggler/fadownloader/PageLog.kt
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,16 @@ class PageLog(activity : Activity, ignored : View) :
var i = 0
var count = cursor.count
if(count <= 0) count = 1
val colidx_time = cursor.getColumnIndex(LogData.COL_TIME)
val colidx_message = cursor.getColumnIndex(LogData.COL_MESSAGE)
val colidx_level = cursor.getColumnIndex(LogData.COL_LEVEL)
val colIdx_time = cursor.getColumnIndex(LogData.COL_TIME)
val colIdx_message = cursor.getColumnIndex(LogData.COL_MESSAGE)
val colIdx_level = cursor.getColumnIndex(LogData.COL_LEVEL)
while(cursor.moveToNext()) {
if(isCancelled) return null
publishProgress(i ++, count)
fos.printf(
"%s %s/%s\n",
LogViewer.date_fmt.format(cursor.getLong(colidx_time)),
LogData.getLogLevelString(cursor.getInt(colidx_level)),
cursor.getString(colidx_message)
)
val date = LogViewer.date_fmt.format(cursor.getLong(colIdx_time))
val level = LogData.getLogLevelString(cursor.getInt(colIdx_level))
val message = cursor.getString(colIdx_message)
fos.print("$date $level/$message\n")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package jp.juggler.fadownloader.tracker

import android.content.Context
import android.location.Location
import android.os.SystemClock
import com.google.android.gms.location.*
import jp.juggler.fadownloader.R
import jp.juggler.fadownloader.util.LogWriter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ class NetworkTracker(
conn.readTimeout = 30000
conn.doOutput = false
conn.connect()
val rcode = conn.responseCode
if(rcode != 200) {
log.e("HTTP error %s. url=%s", rcode, check_url)
val resCode = conn.responseCode
if(resCode != 200) {
log.e("HTTP error %s. url=%s", resCode, check_url)
} else {
if(target_url != last_flash_air_url.get()) {
log.i("target detected. %s", target_url)
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/jp/juggler/fadownloader/util/HTTPClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -727,12 +727,12 @@ class HTTPClient {

//! HTTPレスポンスのヘッダを読む
@Suppress("unused")
fun getHeaderInt(key : String, defval : Int) : Int {
fun getHeaderInt(key : String, defVal : Int) : Int {
val v = getHeaderString(key, null)
return try {
Integer.parseInt(v, 10)
} catch(ex : Throwable) {
defval
defVal
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.ArrayList

object PermissionChecker {

internal val permission_list = arrayOf(
private val permission_list = arrayOf(
Manifest.permission.INTERNET,
Manifest.permission.ACCESS_WIFI_STATE,
Manifest.permission.ACCESS_NETWORK_STATE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import android.content.Context

class ProgressDialogEx(context: Context) : ProgressDialog(context){
companion object {
const val STYLE_SPINNER = ProgressDialog.STYLE_SPINNER
// const val STYLE_SPINNER = ProgressDialog.STYLE_SPINNER
const val STYLE_HORIZONTAL = ProgressDialog.STYLE_HORIZONTAL

}
Expand Down
39 changes: 30 additions & 9 deletions app/src/main/res/layout/act_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="jp.juggler.fadownloader.ActMain"
tools:ignore="SpUsage"
>

<com.google.android.gms.ads.AdView
Expand All @@ -19,17 +20,35 @@
android:background="#000"
/>

<TextView
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#444"
android:orientation="horizontal"
android:background="#969696"
android:gravity="center"
android:padding="6dp"
android:text="@string/app_name"
android:textColor="#fff"
android:textSize="20dp"
android:textStyle="bold"
/>
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center"
android:src="@drawable/ic_app_logo"
android:scaleType="fitCenter"
android:paddingTop="3dp"
android:paddingBottom="3dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="#fff"
android:textStyle="bold"
android:textSize="24dp"
android:layout_marginStart="4dp"
android:layout_marginLeft="4dp"
/>

</LinearLayout>


<LinearLayout
android:id="@+id/llBtnList"
Expand All @@ -38,8 +57,10 @@
android:layout_height="wrap_content"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:gravity="center"
>


<Button
android:id="@+id/btnRepeat"
style="?android:attr/buttonBarButtonStyle"
Expand Down Expand Up @@ -72,7 +93,7 @@
style="?android:attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="48dp"
android:minWidth="40dp"
android:text="@string/question"
/>
</LinearLayout>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/layout/folder_create_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:text="@string/folder_name"
android:labelFor="@+id/etName"
/>

<EditText
Expand All @@ -28,6 +29,7 @@
android:layout_marginTop="8dp"
android:imeOptions="actionDone"
android:inputType="text"
android:hint="@string/folder_name_hint"
/>

<LinearLayout
Expand Down
68 changes: 32 additions & 36 deletions app/src/main/res/layout/new_file_widget.xml
Original file line number Diff line number Diff line change
@@ -1,48 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/llWidget"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="@dimen/widget_margin"
android:background="#80000000"
android:orientation="vertical"
android:padding="4dp"
tools:ignore="SpUsage"
>

<LinearLayout
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#80000000"
android:orientation="vertical"
android:padding="4dp"
android:id="@+id/llWidget"
>
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/app_name"
android:textColor="#fff"
android:textSize="12dp"

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textColor="#fff"
android:textSize="12dp"
android:gravity="center"
/>

/>
<TextView
android:id="@+id/tvCount"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:textColor="#fff"
android:textSize="16dp"
/>

<TextView
android:id="@+id/tvCount"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:textColor="#fff"
android:textSize="16dp"
android:gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/new_file"
android:textColor="#fff"
android:textSize="12dp"
android:gravity="center"
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/new_file"
android:textColor="#fff"
android:textSize="12dp"

/>
</LinearLayout>
/>
</LinearLayout>

</FrameLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/page_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
android:id="@+id/etTargetUrl"
style="@style/setting_edit_text"
android:inputType="textUri"
android:hint="@string/target_url_hint"
/>

<Button
Expand Down Expand Up @@ -110,6 +111,7 @@
android:id="@+id/etFileType"
style="@style/setting_edit_text"
android:inputType="text"
android:hint="@string/file_type_hint"
/>

<Button
Expand Down Expand Up @@ -174,6 +176,7 @@
android:id="@+id/etRepeatInterval"
style="@style/setting_edit_text"
android:inputType="number"
android:hint="@string/repeat_interval_hint"
/>

<Button
Expand Down Expand Up @@ -216,6 +219,7 @@
android:id="@+id/etLocationIntervalDesired"
style="@style/setting_edit_text"
android:inputType="number"
android:hint="@string/location_interval_desired_hint"
/>

<Button
Expand All @@ -238,6 +242,7 @@
android:id="@+id/etLocationIntervalMin"
style="@style/setting_edit_text"
android:inputType="number"
android:hint="@string/location_interval_min_hint"
/>

<Button
Expand Down Expand Up @@ -281,6 +286,7 @@
android:id="@+id/etSSID"
style="@style/setting_edit_text"
android:inputType="text"
android:hint="@string/wifi_ap_ssid_hint"
/>

<Button
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/res/menu/act_main.xml

This file was deleted.

Loading

0 comments on commit c05eae4

Please sign in to comment.