OSDN Git Service

データ送信時のintentの変更(強化)検討中。
authorMRSa <mrsa@myad.jp>
Mon, 17 Apr 2023 15:01:52 +0000 (00:01 +0900)
committerMRSa <mrsa@myad.jp>
Mon, 17 Apr 2023 15:01:52 +0000 (00:01 +0900)
.idea/deploymentTargetDropDown.xml [deleted file]
.idea/misc.xml
mobile/build.gradle
wear/build.gradle
wear/src/main/java/net/osdn/gokigen/joggingtimer/recorddetail/DetailActivity.kt
wear/src/main/java/net/osdn/gokigen/joggingtimer/recorddetail/RecordDetailSetup.java [deleted file]
wear/src/main/java/net/osdn/gokigen/joggingtimer/recorddetail/RecordDetailSetup.kt [new file with mode: 0644]

diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
deleted file mode 100644 (file)
index 509e98b..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project version="4">
-  <component name="deploymentTargetDropDown">
-    <runningDeviceTargetSelectedWithDropDown>
-      <Target>
-        <type value="RUNNING_DEVICE_TARGET" />
-        <deviceKey>
-          <Key>
-            <type value="VIRTUAL_DEVICE_PATH" />
-            <value value="C:\Users\MRSa\.android\avd\Wear_OS_Small_Round_API_30.avd" />
-          </Key>
-        </deviceKey>
-      </Target>
-    </runningDeviceTargetSelectedWithDropDown>
-    <timeTargetWasSelectedWithDropDown value="2023-04-15T12:22:12.467173700Z" />
-  </component>
-</project>
\ No newline at end of file
index c839562..088041e 100644 (file)
@@ -1,4 +1,3 @@
-<?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="DesignSurface">
     <option name="filePathToZoomLevelMap">
index 617957d..89169b5 100644 (file)
@@ -4,10 +4,10 @@ android {
     compileSdkVersion 33
     defaultConfig {
         applicationId "net.osdn.gokigen.joggingtimer"
-        minSdkVersion 14  // 14
+        minSdkVersion 14
         targetSdkVersion 33
         versionCode 100050
-        versionName "1.0.3"
+        versionName "1.0.5"
     }
     buildTypes {
         release {
@@ -16,6 +16,10 @@ android {
         }
     }
     namespace 'net.osdn.gokigen.joggingtimer'
+    compileOptions {
+        sourceCompatibility JavaVersion.VERSION_17
+        targetCompatibility JavaVersion.VERSION_17
+    }
 }
 
 dependencies {
index 5b65d1c..ff3ba0f 100644 (file)
@@ -8,7 +8,7 @@ android {
         minSdkVersion 23
         targetSdkVersion 33
         versionCode 100051
-        versionName "1.0.4"
+        versionName "1.0.5"
     }
     buildTypes {
         release {
@@ -17,7 +17,6 @@ android {
         }
     }
     namespace 'net.osdn.gokigen.joggingtimer'
-
     compileOptions {
         sourceCompatibility JavaVersion.VERSION_17
         targetCompatibility JavaVersion.VERSION_17
@@ -27,6 +26,8 @@ android {
 dependencies {
     implementation fileTree(dir: 'libs', include: ['*.jar'])
     implementation 'com.google.android.support:wearable:2.9.0'
+    //implementation 'com.google.android.gms:play-services-wearable:18.0.0'
+
     implementation 'androidx.preference:preference-ktx:1.2.0'
     implementation "androidx.core:core-splashscreen:1.0.0"
     implementation 'androidx.recyclerview:recyclerview:1.3.0'
index 0b80a94..a1cb4a5 100644 (file)
@@ -1,5 +1,6 @@
 package net.osdn.gokigen.joggingtimer.recorddetail
 
+import android.annotation.SuppressLint
 import android.os.Bundle
 import android.util.Log
 import android.view.MenuItem
@@ -23,37 +24,33 @@ import net.osdn.gokigen.joggingtimer.utilities.SetReferenceDialog
 import net.osdn.gokigen.joggingtimer.utilities.SetReferenceDialog.SetReferenceCallback
 import kotlin.math.roundToInt
 
-/**
- *
- *
- */
 class DetailActivity : AppCompatActivity(),
     RecordDetailSetup.IDatabaseReadyNotify, MenuItem.OnMenuItemClickListener,
     DataEditDialog.Callback, IEditedModelDataCallback, DetailSelectionMenuAdapter.ISelectedMenu,
-    AmbientModeSupport.AmbientCallbackProvider, SetReferenceCallback {
-    private val TAG = toString()
+    AmbientModeSupport.AmbientCallbackProvider, SetReferenceCallback
+{
     private var detailAdapter: RecordDetailAdapter? = null
     private var setupper: RecordDetailSetup? = null
     private var actionDrawerView: WearableActionDrawerView? = null
 
-    /**
-     *
-     */
-    override fun onCreate(savedInstanceState: Bundle?) {
+    override fun onCreate(savedInstanceState: Bundle?)
+    {
         super.onCreate(savedInstanceState)
         Log.v(TAG, "onCreate()")
         setContentView(R.layout.activity_detail)
 
-        // Enables Always-on
-        //setAmbientEnabled();
-        try {
+        try
+        {
             val ambientController = AmbientModeSupport.attach(this)
             ambientController.setAutoResumeEnabled(true)
-            //boolean isAmbient = ambientController.isAmbient();
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
-        try {
+
+        try
+        {
             val naviView = findViewById<WearableNavigationDrawerView>(R.id.top_navigation_drawer)
             val menuAdapter = DetailSelectionMenuAdapter(this, this)
             naviView.setAdapter(menuAdapter)
@@ -62,108 +59,74 @@ class DetailActivity : AppCompatActivity(),
             detailAdapter = RecordDetailAdapter()
             val layoutManager = WearableLinearLayoutManager(this)
 
-            //view.setCircularScrollingGestureEnabled(getResources().getConfiguration().isScreenRound());
             view.isCircularScrollingGestureEnabled = false
             val dividerDecoration = DividerItemDecoration(view.context, layoutManager.orientation)
             view.addItemDecoration(dividerDecoration)
             view.layoutManager = layoutManager
             view.adapter = detailAdapter
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
             detailAdapter = null
         }
 
-        // Bottom Action Drawer
-        actionDrawerView = findViewById(R.id.bottom_action_drawer)
-        actionDrawerView?.controller?.peekDrawer()
-        actionDrawerView?.setOnMenuItemClickListener(this)
-    }
-
-    /**
-     *
-     */
-    override fun onSaveInstanceState(outState: Bundle) {
-        super.onSaveInstanceState(outState)
-    }
-
-    /**
-     *
-     */
-    override fun onRestoreInstanceState(savedInstanceState: Bundle) {
-        super.onRestoreInstanceState(savedInstanceState)
+        try
+        {
+            // Bottom Action Drawer
+            actionDrawerView = findViewById(R.id.bottom_action_drawer)
+            actionDrawerView?.controller?.peekDrawer()
+            actionDrawerView?.setOnMenuItemClickListener(this)
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
     }
 
-    /**
-     *
-     */
-    override fun onResume() {
+    override fun onResume()
+    {
         super.onResume()
         Log.v(TAG, "onResume() ")
     }
 
-    /**
-     *
-     */
-    override fun onPause() {
+    override fun onPause()
+    {
         super.onPause()
         Log.v(TAG, "onPause()")
     }
 
-    /**
-     *
-     *
-     */
-    public override fun onStart() {
+    public override fun onStart()
+    {
         super.onStart()
-        try {
+        try
+        {
             val indexId = intent.getLongExtra(INTENT_EXTRA_DATA_ID, -1)
             Log.v(TAG, "onResume() $indexId")
             setupper = RecordDetailSetup(this, indexId, this, detailAdapter, this)
-            setupper!!.setup()
-        } catch (e: Exception) {
+            setupper?.setup()
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
     }
 
-    /**
-     *
-     *
-     */
-    public override fun onStop() {
+    public override fun onStop()
+    {
         super.onStop()
         Log.v(TAG, "onStop()")
-        try {
-            if (setupper != null) {
-                setupper!!.closeDatabase()
-                setupper = null
-            }
-        } catch (e: Exception) {
+        try
+        {
+            setupper?.closeDatabase()
+            setupper = null
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
         System.gc()
     }
-    /*
-    @Override
-    public void onEnterAmbient(Bundle ambientDetails)
-    {
-        super.onEnterAmbient(ambientDetails);
-        Log.v(TAG, "onEnterAmbient()");
-    }
-
-    @Override
-    public void onExitAmbient()
-    {
-        super.onExitAmbient();
-        Log.v(TAG, "onExitAmbient()");
-    }
-
-    @Override
-    public void onUpdateAmbient()
-    {
-        super.onUpdateAmbient();
-        Log.v(TAG, "onUpdateAmbient()");
-    }
-*/
 
     override fun onGenericMotionEvent(ev: MotionEvent?): Boolean
     {
@@ -187,25 +150,18 @@ class DetailActivity : AppCompatActivity(),
         return (super.onGenericMotionEvent(ev))
     }
 
-
-    /**
-     *
-     *
-     */
-    override fun databaseSetupFinished(result: Boolean) {
+    override fun databaseSetupFinished(result: Boolean)
+    {
         Log.v(TAG, "databaseSetupFinished() : $result")
     }
 
-    /**
-     *
-     *
-     */
-    override fun updatedIndexData(isIconOnly: Boolean) {
+    override fun updatedIndexData(isIconOnly: Boolean)
+    {
         Log.v(TAG, "selectedReferenceData() : $isIconOnly")
         runOnUiThread {
-            try {
-                val title: String
-                title = if (isIconOnly) {
+            try
+            {
+                val title: String = if (isIconOnly) {
                     getString(R.string.action_set_reference)
                 } else {
                     getString(R.string.action_edited_data)
@@ -213,187 +169,187 @@ class DetailActivity : AppCompatActivity(),
                 val toast =
                     Toast.makeText(applicationContext, title, Toast.LENGTH_SHORT)
                 toast.show()
-            } catch (e: Exception) {
+            }
+            catch (e: Exception)
+            {
                 e.printStackTrace()
             }
         }
     }
 
-    /**
-     *
-     *
-     */
-    override fun onMenuItemClick(item: MenuItem): Boolean {
+    override fun onMenuItemClick(item: MenuItem): Boolean
+    {
         Log.v(TAG, "onMenuItemClick(): $item")
         val itemId = item.itemId
-        try {
-            actionDrawerView!!.controller.closeDrawer()
-        } catch (e: Exception) {
+        try
+        {
+            actionDrawerView?.controller?.closeDrawer()
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
-        return itemSelected(itemId)
+        return (itemSelected(itemId))
     }
 
-    private fun itemSelected(itemId: Int): Boolean {
+    private fun itemSelected(itemId: Int): Boolean
+    {
         var ret = false
-        //String toastMessage = "";
-        if (itemId == R.id.menu_edit_title) {
-            // タイトルの編集
-            var title = ""
-            var iconId = R.drawable.ic_android_black_24dp
-            val data = setupper!!.editIndexData
-            if (data != null) {
-                iconId = data.getIcon()
-                title = data.getTitle()
+        when (itemId) {
+            R.id.menu_edit_title -> {
+                // タイトルの編集
+                var title = ""
+                var iconId = R.drawable.ic_android_black_24dp
+                val data = setupper?.getEditIndexData()
+                if (data != null)
+                {
+                    iconId = data.icon()
+                    title = data.title()
+                }
+                val dialog = DataEditDialog.newInstance(iconId, title, this)
+                val manager = supportFragmentManager
+                dialog.show(manager, "dialog")
+                true.also { ret = it }
             }
-            val dialog = DataEditDialog.newInstance(iconId, title, this)
-            val manager = supportFragmentManager
-            dialog.show(manager, "dialog")
-            ret = true
-        } else if (itemId == R.id.menu_set_reference) {
-            // 基準値の設定ダイアログを表示する
-            val callback: SetReferenceCallback = this
-            runOnUiThread {
-                try {
-                    // 基準値設定ダイアログを表示する
-                    val dialog = SetReferenceDialog.newInstance(callback)
-                    val manager = supportFragmentManager
-                    dialog.show(manager, "dialog")
-                } catch (e: Exception) {
-                    e.printStackTrace()
+            R.id.menu_set_reference -> {
+                // 基準値の設定ダイアログを表示する
+                val callback: SetReferenceCallback = this
+                runOnUiThread {
+                    try {
+                        // 基準値設定ダイアログを表示する
+                        val dialog = SetReferenceDialog.newInstance(callback)
+                        val manager = supportFragmentManager
+                        dialog.show(manager, "dialog")
+                    } catch (e: Exception) {
+                        e.printStackTrace()
+                    }
                 }
+                true.also { ret = it }
             }
-            ret = true
-        } else if (itemId == R.id.menu_share_data) {
-            // 現在のデータを共有する
-            setupper!!.shareTheData(detailAdapter)
-            ret = true
-        }
-        /*
-        try
-        {
-            if (toastMessage.length() > 0)
-            {
-                Toast toast = Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_SHORT);
-                toast.show();
+            R.id.menu_share_data -> {
+                // 現在のデータを共有する
+                setupper?.shareTheData(detailAdapter)
+                true.also { ret = it }
             }
         }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-*/return ret
+        return ret
     }
 
-    /**
-     *
-     */
-    override fun dataEdited(iconId: Int, title: String) {
+    override fun dataEdited(iconId: Int, title: String)
+    {
         Log.v(TAG, "iconId : $iconId title : '$title'")
-        try {
-            setupper!!.setEditIndexData(title, iconId)
+        try
+        {
+            setupper?.setEditIndexData(title, iconId)
             val view = findViewById<WearableRecyclerView>(R.id.recycler_detail_view)
             view.postInvalidate()
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
     }
 
-    /**
-     *
-     */
-    private fun updateScreen() {
-        try {
+    private fun updateScreen()
+    {
+        try
+        {
             val view = findViewById<WearableRecyclerView>(R.id.recycler_detail_view)
             view.postInvalidate()
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
     }
 
-    /**
-     *
-     */
-    override fun cancelled() {
+    override fun cancelled()
+    {
         updateScreen()
     }
 
-    /**
-     *
-     */
+    @SuppressLint("NotifyDataSetChanged")
     override fun editedModelData(
         indexId: Long,
         detailId: Long,
         lapCount: Int,
         prevTime: Long,
         newTime: Long
-    ) {
+    )
+    {
         Log.v(
             TAG,
             "editedModelData() $indexId $detailId $lapCount ($prevTime -> $newTime)"
         )
-        if (detailAdapter == null) {
+        if (detailAdapter == null)
+        {
             return
         }
         val diffTime = newTime - prevTime
-        val count = detailAdapter!!.itemCount
-        if (count > 1) {
+        val count = detailAdapter?.itemCount ?: 0
+        if (count > 1)
+        {
             var totalTime: Long = 0
             val modTime = diffTime * -1 / (count - 1)
-            for (index in 1..count) {
-                val record = detailAdapter!!.getRecord(index - 1)
+            for (index in 1..count)
+            {
+                val record = detailAdapter?.getRecord(index - 1)
                 totalTime = if (lapCount == index) {
-                    record.addModifiedTime(diffTime, totalTime)
+                    record?.addModifiedTime(diffTime, totalTime) ?: 0
                 } else {
-                    record.addModifiedTime(modTime, totalTime)
+                    record?.addModifiedTime(modTime, totalTime) ?: 0
                 }
-                detailAdapter!!.notifyItemChanged(index - 1)
+                detailAdapter?.notifyItemChanged(index - 1)
             }
-            try {
+            try
+            {
                 val thread = Thread {
-                    if (setupper != null) {
-                        setupper!!.updateDatabaseRecord(detailAdapter!!)
+                    if (setupper != null)
+                    {
+                        setupper?.updateDatabaseRecord(detailAdapter!!)
                     }
                 }
                 thread.start()
-            } catch (e: Exception) {
+            }
+            catch (e: Exception)
+            {
                 e.printStackTrace()
             }
         }
-        try {
+        try
+        {
             detailAdapter?.notifyDataSetChanged()
-        } catch (e: Exception) {
+        }
+        catch (e: Exception)
+        {
             e.printStackTrace()
         }
     }
 
-    override fun selectedMenu(itemId: Int) {
+    override fun selectedMenu(itemId: Int)
+    {
         itemSelected(itemId)
     }
 
-    override fun getAmbientCallback(): AmbientModeSupport.AmbientCallback {
+    override fun getAmbientCallback(): AmbientModeSupport.AmbientCallback
+    {
         return object : AmbientModeSupport.AmbientCallback() {
-            override fun onEnterAmbient(ambientDetails: Bundle) {
+            override fun onEnterAmbient(ambientDetails: Bundle)
+            {
                 Log.v(TAG, "onEnterAmbient()")
             }
-
-            fun onExitAmbient(ambientDetails: Bundle?) {
-                Log.v(TAG, "onExitAmbient()")
-            }
         }
     }
 
-    override fun onPointerCaptureChanged(hasCapture: Boolean) {
-        super.onPointerCaptureChanged(hasCapture)
-    }
-
-    override fun confirmed(id: Int) {
+    override fun confirmed(id: Int)
+    {
         // 現在のデータを基準値として設定する
         Log.v(TAG, " SET REFERENCE DATA ID: $id")
-        setupper!!.setReferenceData(id)
+        setupper?.setReferenceData(id)
     }
 
     companion object {
+        private val TAG = DetailActivity::class.java.simpleName
         const val INTENT_EXTRA_DATA_ID = "Detail.dataId"
     }
-}
\ No newline at end of file
+}
diff --git a/wear/src/main/java/net/osdn/gokigen/joggingtimer/recorddetail/RecordDetailSetup.java b/wear/src/main/java/net/osdn/gokigen/joggingtimer/recorddetail/RecordDetailSetup.java
deleted file mode 100644 (file)
index 42aadc0..0000000
+++ /dev/null
@@ -1,396 +0,0 @@
-package net.osdn.gokigen.joggingtimer.recorddetail;
-
-import android.annotation.SuppressLint;
-import android.content.Intent;
-import android.database.Cursor;
-import android.util.Log;
-
-import net.osdn.gokigen.joggingtimer.R;
-import net.osdn.gokigen.joggingtimer.storage.ITimeEntryDatabase;
-import net.osdn.gokigen.joggingtimer.storage.ITimeEntryDatabaseCallback;
-import net.osdn.gokigen.joggingtimer.storage.TimeEntryDatabaseFactory;
-import net.osdn.gokigen.joggingtimer.storage.contract.TimeEntryData;
-import net.osdn.gokigen.joggingtimer.storage.contract.TimeEntryIndex;
-import net.osdn.gokigen.joggingtimer.utilities.CreateModelData;
-import net.osdn.gokigen.joggingtimer.utilities.CreateModelDataDialog;
-import net.osdn.gokigen.joggingtimer.utilities.TimeStringConvert;
-
-import static android.provider.BaseColumns._ID;
-import static net.osdn.gokigen.joggingtimer.storage.contract.TimeEntryIndex.EntryIndex.COLUMN_NAME_MEMO;
-import static net.osdn.gokigen.joggingtimer.storage.contract.TimeEntryIndex.EntryIndex.COLUMN_NAME_START_TIME;
-import static net.osdn.gokigen.joggingtimer.storage.contract.TimeEntryIndex.EntryIndex.COLUMN_NAME_TIME_DURATION;
-import static net.osdn.gokigen.joggingtimer.storage.contract.TimeEntryIndex.EntryIndex.COLUMN_NAME_TITLE;
-
-import androidx.annotation.NonNull;
-import androidx.appcompat.app.AppCompatActivity;
-
-/**
- *
- *
- */
-public class RecordDetailSetup  implements ITimeEntryDatabaseCallback, IDetailEditor
-{
-    private final String TAG = toString();
-    private final AppCompatActivity activity;
-    private final long indexId;
-    private final IDatabaseReadyNotify callback;
-    private final IRecordOperation operation;
-    private final CreateModelData.IEditedModelDataCallback editCallback;
-    private ITimeEntryDatabase database = null;
-
-    /**
-     *
-     *
-     */
-    RecordDetailSetup(AppCompatActivity activity, long indexId, IDatabaseReadyNotify callback, IRecordOperation operation, CreateModelData.IEditedModelDataCallback  editCallback)
-    {
-        this.activity = activity;
-        this.indexId = indexId;
-        this.callback = callback;
-        this.operation = operation;
-        this.editCallback = editCallback;
-    }
-
-    /**
-     *
-     *
-     */
-    void setup()
-    {
-        Log.v(TAG, "setup()");
-        database = new TimeEntryDatabaseFactory(activity, this).getEntryDatabase();
-        Thread thread = new Thread(() -> {
-            try
-            {
-                database.prepare();
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-        });
-        thread.start();
-    }
-
-    /**
-     *
-     *
-     */
-    @Override
-    public void prepareFinished(boolean isReady)
-    {
-        if (!isReady)
-        {
-            callback.databaseSetupFinished(false);
-            return;
-        }
-        final IDetailEditor editor = this;
-        Thread thread = new Thread(() -> {
-            boolean ret = false;
-            try
-            {
-                operation.clearRecord();
-                Cursor cursor = database.getAllDetailData(indexId);
-                int index = 0;
-                long startTime = 0;
-                long previousLapTime = 0;
-                long morePreviousTime = 0;
-                while (cursor.moveToNext())
-                {
-                    @SuppressLint("Range") long dataId = cursor.getLong(cursor.getColumnIndex(_ID));
-                    @SuppressLint("Range") long indexId = cursor.getLong(cursor.getColumnIndex(TimeEntryData.EntryData.COLUMN_NAME_INDEX_ID));
-                    @SuppressLint("Range") long entryTime = cursor.getLong(cursor.getColumnIndex(TimeEntryData.EntryData.COLUMN_NAME_TIME_ENTRY));
-                    @SuppressLint("Range") int recordType = cursor.getInt(cursor.getColumnIndex(TimeEntryData.EntryData.COLUMN_NAME_RECORD_TYPE));
-
-                    if (index == 0)
-                    {
-                        // first record
-                        startTime = entryTime;
-                        previousLapTime = entryTime;
-                        morePreviousTime = entryTime;
-                    }
-                    else
-                    {
-                        long lapTime = entryTime - previousLapTime;
-                        long overallTime = entryTime - startTime;
-                        long differenceTime = (lapTime) - (previousLapTime - morePreviousTime);
-                        operation.addRecord(new DetailRecord(indexId, dataId, recordType, index, lapTime, overallTime, differenceTime,  editor));
-                        morePreviousTime = previousLapTime;
-                        previousLapTime = entryTime;
-                    }
-                    index++;
-                }
-                activity.runOnUiThread(operation::dataSetChangeFinished);
-                ret = true;
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-            callback.databaseSetupFinished(ret);
-        });
-        thread.start();
-    }
-
-    /**
-     *
-     *
-     */
-    void setEditIndexData(@NonNull final String title, final int icon)
-    {
-        final EditIndexData data = new EditIndexData(title, icon);
-        Thread thread = new Thread(() -> {
-            database.updateIndexData(indexId, data.getTitle(), data.getIcon());
-            callback.updatedIndexData(false);
-        });
-        thread.start();
-    }
-
-    /**
-     *
-     *
-     */
-    @SuppressLint("Range")
-    EditIndexData getEditIndexData()
-    {
-        String title = "";
-        int iconId = R.drawable.ic_android_black_24dp;
-        try
-        {
-            Cursor cursor = database.getIndexdata(indexId);
-            while (cursor.moveToNext())
-            {
-                title = cursor.getString(cursor.getColumnIndex(TimeEntryIndex.EntryIndex.COLUMN_NAME_TITLE));
-                iconId = cursor.getInt(cursor.getColumnIndex(TimeEntryIndex.EntryIndex.COLUMN_NAME_ICON_ID));
-            }
-            return (new EditIndexData(title, iconId));
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-        return (null);
-    }
-
-    /**
-     *
-     *
-     */
-    void setReferenceData(final int id)
-    {
-        Thread thread = new Thread(() -> {
-            database.setReferenceIndexData(id, indexId);
-            callback.updatedIndexData(true);
-        });
-        thread.start();
-    }
-
-    /**
-     *
-     *
-     */
-    @Override
-    public void dataEntryFinished(OperationType operationType, boolean result, long id, String title)
-    {
-         //
-    }
-
-    /**
-     *
-     *
-     */
-    @Override
-    public void timeEntryFinished(OperationType operationType, boolean result, long indexId, long dataId)
-    {
-        //
-    }
-
-    @Override
-    public void modelDataEntryFinished(OperationType operationType, boolean result, long indexId, String title)
-    {
-        //
-        Log.v(TAG, "modelDataEntryFinished : " + result + " " + title + " " + indexId);
-    }
-
-    /**
-     *
-     */
-    void closeDatabase()
-    {
-        try
-        {
-            database.close();
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-    }
-
-    /**
-     *    IDetailEditor.editDetailData()
-     */
-    @Override
-    public void editDetailData(final long indexId, final long dataId, final int count, final long defaultMillis)
-    {
-        activity.runOnUiThread(() -> {
-            CreateModelDataDialog dialog2 = CreateModelDataDialog.newInstance(false, activity.getString(R.string.information_modify_time), count, new CreateModelData(database, editCallback, null, indexId, dataId), defaultMillis);
-            dialog2.showNow(activity.getSupportFragmentManager(), "dialog2");
-        });
-    }
-
-    /**
-     *
-     */
-    public void updateDatabaseRecord(@NonNull RecordDetailAdapter adapter)
-    {
-        try
-        {
-            int count = adapter.getItemCount();
-            if (count > 1)
-            {
-                for (int index = 0; index < count; index++)
-                {
-                    DetailRecord record = adapter.getRecord(index);
-                    long id = record.getDataId();
-                    long time = record.getTotalTime();
-                    database.updateTimeEntryData(id, time);
-                }
-            }
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-    }
-
-    /**
-     *   現在のデータを共有する
-     *
-     */
-    public void shareTheData(final RecordDetailAdapter adapter)
-    {
-        Log.v(TAG, "shareTheData()");
-        if ((adapter == null) || (adapter.getItemCount() <= 0) || (activity == null))
-        {
-            // データがない場合は、何もしない
-            return;
-        }
-        shareDetailIntent(adapter);
-    }
-
-
-    /**
-     *
-     *
-     */
-    @SuppressLint("Range")
-    private void shareDetailIntent(RecordDetailAdapter adapter)
-    {
-        String title = "";
-        int dataCount = adapter.getItemCount();
-        StringBuilder dataToExport = new StringBuilder();
-        dataToExport.append("; ");
-        dataToExport.append(activity.getString(R.string.app_name));
-        dataToExport.append("\r\n");
-        try
-        {
-            Cursor cursor = database.getIndexdata(indexId);
-            while (cursor.moveToNext())
-            {
-                dataToExport.append("; ");
-                title = cursor.getString(cursor.getColumnIndex(COLUMN_NAME_TITLE));
-                dataToExport.append(title);
-                dataToExport.append(",");
-                dataToExport.append(TimeStringConvert.getTimeString(cursor.getLong(cursor.getColumnIndex(COLUMN_NAME_TIME_DURATION))));
-                dataToExport.append(",");
-                dataToExport.append(cursor.getLong(cursor.getColumnIndex(COLUMN_NAME_START_TIME)));
-                dataToExport.append(",");
-                dataToExport.append(cursor.getString(cursor.getColumnIndex(COLUMN_NAME_MEMO)));
-                dataToExport.append(",");
-                dataToExport.append("\r\n");
-            }
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-            dataToExport.append("\r\n");
-        }
-        dataToExport.append("; \r\n");
-        dataToExport.append("; LapCount,LapTime,TotalTime,LapTime(ms),TotalTime(ms),;\r\n");
-
-        for (int index = 0; index < dataCount; index++)
-        {
-            try
-            {
-                DetailRecord record = adapter.getRecord(index);
-                dataToExport.append(record.getLapCount());
-                dataToExport.append(",");
-                dataToExport.append(record.getTitle());
-                dataToExport.append(",");
-                dataToExport.append(record.getOverallTime());
-                dataToExport.append(",");
-                dataToExport.append(record.getLapTime());
-                dataToExport.append(",");
-                dataToExport.append(record.getTotalTime());
-                dataToExport.append(",");
-                dataToExport.append(";");
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-                dataToExport.append(";;\r\n");
-                break;
-            }
-            dataToExport.append("\r\n");
-        }
-
-        // Intent発行(ACTION_SEND)
-        try
-        {
-            Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
-            sendIntent.putExtra(Intent.EXTRA_SUBJECT, title);
-            sendIntent.setType("text/plain");
-            sendIntent.putExtra(Intent.EXTRA_TEXT, dataToExport.toString());
-            activity.startActivity(sendIntent);
-
-            Log.v(TAG, "<<< SEND INTENT >>> : " + title);
-        }
-        catch (Exception e)
-        {
-            e.printStackTrace();
-        }
-    }
-
-    static class EditIndexData
-    {
-        final String title;
-        final int icon;
-
-        EditIndexData(String title, int icon)
-        {
-            this.title = title;
-            this.icon = icon;
-        }
-
-        String getTitle()
-        {
-            return (title);
-        }
-
-        int getIcon()
-        {
-            return (icon);
-        }
-    }
-
-
-    /**
-     *
-     */
-    interface IDatabaseReadyNotify
-    {
-        void databaseSetupFinished(boolean result);
-        void updatedIndexData(boolean isIconOnly);
-    }
-}
diff --git a/wear/src/main/java/net/osdn/gokigen/joggingtimer/recorddetail/RecordDetailSetup.kt b/wear/src/main/java/net/osdn/gokigen/joggingtimer/recorddetail/RecordDetailSetup.kt
new file mode 100644 (file)
index 0000000..0b48a50
--- /dev/null
@@ -0,0 +1,349 @@
+package net.osdn.gokigen.joggingtimer.recorddetail
+
+import android.annotation.SuppressLint
+import android.content.Intent
+import android.provider.BaseColumns
+import android.util.Log
+import androidx.appcompat.app.AppCompatActivity
+import net.osdn.gokigen.joggingtimer.R
+import net.osdn.gokigen.joggingtimer.storage.ITimeEntryDatabase
+import net.osdn.gokigen.joggingtimer.storage.ITimeEntryDatabaseCallback
+import net.osdn.gokigen.joggingtimer.storage.ITimeEntryDatabaseCallback.OperationType
+import net.osdn.gokigen.joggingtimer.storage.TimeEntryDatabaseFactory
+import net.osdn.gokigen.joggingtimer.storage.contract.TimeEntryData
+import net.osdn.gokigen.joggingtimer.storage.contract.TimeEntryIndex.EntryIndex
+import net.osdn.gokigen.joggingtimer.utilities.CreateModelData
+import net.osdn.gokigen.joggingtimer.utilities.CreateModelData.IEditedModelDataCallback
+import net.osdn.gokigen.joggingtimer.utilities.CreateModelDataDialog
+import net.osdn.gokigen.joggingtimer.utilities.TimeStringConvert
+
+
+class RecordDetailSetup internal constructor(
+    private val activity: AppCompatActivity,
+    private val indexId: Long,
+    private val callback: IDatabaseReadyNotify,
+    private val operation: IRecordOperation?,
+    private val editCallback: IEditedModelDataCallback
+) : ITimeEntryDatabaseCallback, IDetailEditor
+{
+    private var database: ITimeEntryDatabase? = null
+    fun setup()
+    {
+        Log.v(TAG, "setup()")
+        database = TimeEntryDatabaseFactory(activity, this).entryDatabase
+        val thread = Thread {
+            try
+            {
+                database?.prepare()
+            }
+            catch (e: Exception)
+            {
+                e.printStackTrace()
+            }
+        }
+        thread.start()
+    }
+
+    override fun prepareFinished(isReady: Boolean)
+    {
+        if (!isReady)
+        {
+            callback.databaseSetupFinished(false)
+            return
+        }
+        val editor: IDetailEditor = this
+        val thread = Thread {
+            var ret = false
+            try
+            {
+                operation?.clearRecord()
+                val cursor = database?.getAllDetailData(indexId)
+                var index = 0
+                var startTime: Long = 0
+                var previousLapTime: Long = 0
+                var morePreviousTime: Long = 0
+                while (cursor?.moveToNext() == true)
+                {
+                    val dataIdIndex = cursor.getColumnIndex(BaseColumns._ID)
+                    val dataId = cursor.getLong(dataIdIndex)
+
+                    val indexIdIndex = cursor.getColumnIndex(TimeEntryData.EntryData.COLUMN_NAME_INDEX_ID)
+                    val indexId = cursor.getLong(indexIdIndex)
+
+                    val entryTimeIndex = cursor.getColumnIndex(TimeEntryData.EntryData.COLUMN_NAME_TIME_ENTRY)
+                    val entryTime = cursor.getLong(entryTimeIndex)
+
+                    val recordTypeIndex = cursor.getColumnIndex(TimeEntryData.EntryData.COLUMN_NAME_RECORD_TYPE)
+                    val recordType = cursor.getInt(recordTypeIndex)
+                    if (index == 0)
+                    {
+                        // first record
+                        startTime = entryTime
+                        previousLapTime = entryTime
+                        morePreviousTime = entryTime
+                    }
+                    else
+                    {
+                        val lapTime = entryTime - previousLapTime
+                        val overallTime = entryTime - startTime
+                        val differenceTime =
+                            lapTime - (previousLapTime - morePreviousTime)
+                        operation?.addRecord(
+                            DetailRecord(
+                                indexId,
+                                dataId,
+                                recordType,
+                                index,
+                                lapTime,
+                                overallTime,
+                                differenceTime,
+                                editor
+                            )
+                        )
+                        morePreviousTime = previousLapTime
+                        previousLapTime = entryTime
+                    }
+                    index++
+                }
+                activity.runOnUiThread { operation?.dataSetChangeFinished() }
+                ret = true
+            }
+            catch (e: Exception)
+            {
+                e.printStackTrace()
+            }
+            callback.databaseSetupFinished(ret)
+        }
+        thread.start()
+    }
+
+    fun setEditIndexData(title: String, icon: Int)
+    {
+        val data = EditIndexData(title, icon)
+        val thread = Thread {
+            database?.updateIndexData(indexId, data.title(), data.icon())
+            callback.updatedIndexData(false)
+        }
+        thread.start()
+    }
+
+    fun getEditIndexData(): EditIndexData?
+    {
+        var title = ""
+        var iconId: Int = R.drawable.ic_android_black_24dp
+        try
+        {
+            val cursor = database?.getIndexdata(indexId)
+            while (cursor?.moveToNext() == true)
+            {
+                val titleIndex = cursor.getColumnIndex(EntryIndex.COLUMN_NAME_TITLE)
+                title = cursor.getString(titleIndex)
+
+                val iconIdIndex = cursor.getColumnIndex(EntryIndex.COLUMN_NAME_ICON_ID)
+                iconId = cursor.getInt(iconIdIndex)
+            }
+            return EditIndexData(title, iconId)
+        }
+        catch (e: java.lang.Exception)
+        {
+            e.printStackTrace()
+        }
+        return (null)
+    }
+
+    fun setReferenceData(id: Int)
+    {
+        val thread = Thread {
+            database?.setReferenceIndexData(id, indexId)
+            callback.updatedIndexData(true)
+        }
+        thread.start()
+    }
+
+    override fun dataEntryFinished(operationType: OperationType, result: Boolean, id: Long, title: String) { }
+    override fun timeEntryFinished(operationType: OperationType, result: Boolean, indexId: Long, dataId: Long) { }
+    override fun modelDataEntryFinished(operationType: OperationType, result: Boolean, indexId: Long, title: String)
+    {
+        Log.v(TAG, "modelDataEntryFinished : $result $title $indexId")
+    }
+
+    fun closeDatabase()
+    {
+        try
+        {
+            database?.close()
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+    }
+
+    /**
+     * IDetailEditor.editDetailData()
+     */
+    override fun editDetailData(indexId: Long, dataId: Long, count: Int, defaultMillis: Long)
+    {
+        activity.runOnUiThread {
+            val dialog2 = CreateModelDataDialog.newInstance(
+                false,
+                activity.getString(R.string.information_modify_time),
+                count,
+                CreateModelData(
+                    database,
+                    editCallback, null, indexId, dataId
+                ),
+                defaultMillis
+            )
+            dialog2.showNow(activity.supportFragmentManager, "dialog2")
+        }
+    }
+
+    fun updateDatabaseRecord(adapter: RecordDetailAdapter)
+    {
+        try
+        {
+            val count = adapter.itemCount
+            if (count > 1)
+            {
+                for (index in 0 until count)
+                {
+                    val record = adapter.getRecord(index)
+                    val id = record.dataId
+                    val time = record.totalTime
+                    database!!.updateTimeEntryData(id, time)
+                }
+            }
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+    }
+
+    /**
+     * 現在のデータを共有する
+     *
+     */
+    fun shareTheData(adapter: RecordDetailAdapter?)
+    {
+        Log.v(TAG, "shareTheData()")
+        if (adapter == null || adapter.itemCount <= 0 )
+        {
+            // データがない場合は、何もしない
+            Log.v(TAG, "DATA IS NONE, NOT EXPORTED")
+            return
+        }
+        shareDetailIntent(adapter)
+    }
+
+    @SuppressLint("Range")
+    private fun shareDetailIntent(adapter: RecordDetailAdapter)
+    {
+        var title = ""
+        val dataCount = adapter.itemCount
+        val dataToExport = StringBuilder()
+        dataToExport.append("; ")
+        dataToExport.append(activity.getString(R.string.app_name))
+        dataToExport.append("\r\n")
+        try
+        {
+            val cursor = database?.getIndexdata(indexId)
+            while (cursor?.moveToNext() == true) {
+                dataToExport.append("; ")
+                title = cursor.getString(cursor.getColumnIndex(EntryIndex.COLUMN_NAME_TITLE))
+                dataToExport.append(title)
+                dataToExport.append(",")
+                dataToExport.append(
+                    TimeStringConvert.getTimeString(
+                        cursor.getLong(
+                            cursor.getColumnIndex(
+                                EntryIndex.COLUMN_NAME_TIME_DURATION
+                            )
+                        )
+                    )
+                )
+                dataToExport.append(",")
+                dataToExport.append(cursor.getLong(cursor.getColumnIndex(EntryIndex.COLUMN_NAME_START_TIME)))
+                dataToExport.append(",")
+                dataToExport.append(cursor.getString(cursor.getColumnIndex(EntryIndex.COLUMN_NAME_MEMO)))
+                dataToExport.append(",")
+                dataToExport.append("\r\n")
+            }
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+            dataToExport.append("\r\n")
+        }
+        dataToExport.append("; \r\n")
+        dataToExport.append("; LapCount,LapTime,TotalTime,LapTime(ms),TotalTime(ms),;\r\n")
+        for (index in 0 until dataCount)
+        {
+            try
+            {
+                val record = adapter.getRecord(index)
+                dataToExport.append(record.lapCount)
+                dataToExport.append(",")
+                dataToExport.append(record.title)
+                dataToExport.append(",")
+                dataToExport.append(record.overallTime)
+                dataToExport.append(",")
+                dataToExport.append(record.lapTime)
+                dataToExport.append(",")
+                dataToExport.append(record.totalTime)
+                dataToExport.append(",")
+                dataToExport.append(";")
+            }
+            catch (e: Exception)
+            {
+                e.printStackTrace()
+                dataToExport.append(";;\r\n")
+                break
+            }
+            dataToExport.append("\r\n")
+        }
+
+        // Intent発行(ACTION_SEND)
+        try
+        {
+            val sendIntent = Intent().apply {
+                action = Intent.ACTION_SEND  // NoteIntents.ACTION_CREATE_NOTE
+                type = "text/plain"
+                putExtra(Intent.EXTRA_SUBJECT, title)
+                putExtra(Intent.EXTRA_TEXT, dataToExport.toString())
+            }
+            //val shareIntent = Intent.createChooser(sendIntent, null)
+            //activity.startActivity(shareIntent)
+            activity.startActivity(sendIntent)
+            Log.v(TAG, "<<< SEND INTENT >>> : $title")
+        }
+        catch (e: Exception)
+        {
+            e.printStackTrace()
+        }
+    }
+
+    class EditIndexData(val title: String, val icon: Int)
+    {
+        fun title(): String
+        {
+            return (title)
+        }
+
+        fun icon(): Int
+        {
+            return (icon)
+        }
+    }
+
+    internal interface IDatabaseReadyNotify
+    {
+        fun databaseSetupFinished(result: Boolean)
+        fun updatedIndexData(isIconOnly: Boolean)
+    }
+
+    companion object {
+        private val TAG = RecordDetailSetup::class.java.simpleName
+    }
+}