forked from ligi/IPFSDroid
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove binaries now option to load them from ipfs.io
Migrate more code to kotlin Use the IPFS Kotlin API
- Loading branch information
Showing
25 changed files
with
616 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package org.ligi.ipfsdroid | ||
|
||
import android.content.ClipData | ||
import android.content.ClipboardManager | ||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.support.design.widget.Snackbar | ||
import android.support.v7.app.AppCompatActivity | ||
import android.view.Menu | ||
import android.view.MenuItem | ||
import android.widget.TextView | ||
import io.ipfs.kotlin.IPFS | ||
import io.ipfs.kotlin.model.NamedHash | ||
import net.steamcrafted.loadtoast.LoadToast | ||
import org.ligi.axt.AXT | ||
import org.ligi.tracedroid.logging.Log | ||
import javax.inject.Inject | ||
|
||
class AddIPFSContent : AppCompatActivity() { | ||
|
||
@Inject | ||
lateinit var ipfs:IPFS | ||
|
||
val hashText by lazy { findViewById(R.id.hash) as TextView } | ||
var addResult: NamedHash? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
App.component().inject(this) | ||
setContentView(R.layout.activity_add) | ||
|
||
if (Intent.ACTION_SEND == intent.action && intent.type != null) { | ||
if ("text/plain" == intent.type) { | ||
handleSendText(intent) // Handle text being sent | ||
} else { | ||
handleSendStream(intent) // Handle single image being sent | ||
} | ||
} | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu?): Boolean { | ||
menuInflater.inflate(R.menu.add, menu) | ||
return super.onCreateOptionsMenu(menu) | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem?): Boolean { | ||
when (item!!.itemId) { | ||
R.id.copy -> { | ||
val clipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager; | ||
val clip = ClipData.newPlainText("hash", addResult?.Hash); | ||
clipboardManager.primaryClip = clip; | ||
|
||
Snackbar.make(hashText, "copy " + addResult?.Hash, Snackbar.LENGTH_LONG).show() | ||
return true | ||
} | ||
} | ||
return super.onOptionsItemSelected(item) | ||
} | ||
|
||
internal fun handleSendText(intent: Intent) { | ||
val sharedText = intent.getStringExtra(Intent.EXTRA_TEXT) | ||
if (sharedText != null) { | ||
addWithUI { IPFS().add.string(sharedText) } | ||
} | ||
} | ||
|
||
internal fun handleSendStream(intent: Intent) { | ||
val imageUri = intent.getParcelableExtra<Uri>(Intent.EXTRA_STREAM) | ||
val file = AXT.at(imageUri).loadImage(this) | ||
|
||
addWithUI { ipfs.add.file(file) } | ||
} | ||
|
||
fun addWithUI(callback: () -> NamedHash) { | ||
|
||
val show = LoadToast(this).show() | ||
|
||
Thread(Runnable { | ||
addResult = callback() | ||
runOnUiThread { | ||
val displayString: String | ||
if (addResult == null) { | ||
show.error() | ||
displayString = "could not execute add ( daemon running? )" | ||
} else { | ||
show.success() | ||
displayString = "added /ipfs/" + addResult!!.Hash | ||
} | ||
|
||
Log.i(displayString) | ||
|
||
hashText.text = displayString | ||
|
||
} | ||
}).start() | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package org.ligi.ipfsdroid | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.support.v7.app.AlertDialog | ||
import android.support.v7.app.AppCompatActivity | ||
import android.widget.EditText | ||
import android.widget.TextView | ||
import io.ipfs.kotlin.IPFS | ||
import javax.inject.Inject | ||
|
||
class DetailsActivity : AppCompatActivity() { | ||
|
||
val versionTextView by lazy { findViewById(R.id.version) as TextView } | ||
val bandWidthTextView by lazy { findViewById(R.id.bandWidth) as TextView } | ||
val textEdit by lazy { findViewById(R.id.textEdit) as EditText } | ||
|
||
@Inject | ||
lateinit var ipfs: IPFS | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
App.component().inject(this) | ||
setContentView(R.layout.activity_details) | ||
title = "IPFSDroid Info" | ||
|
||
Thread(Runnable { | ||
val version = ipfs.info.version() | ||
val bandWidth = ipfs.stats.bandWidth() | ||
|
||
runOnUiThread { | ||
versionTextView.text = "Version: ${version.Version} \nRepo: ${version.Repo}" | ||
bandWidthTextView.text = "TotlalIn: ${bandWidth.TotalIn} \nTotalOut: ${bandWidth.TotalOut}"+ | ||
"\nRateIn: ${bandWidth.RateIn}\nRateOut: ${bandWidth.RateOut}" | ||
} | ||
}).start() | ||
|
||
findViewById(R.id.addTextCommand)!!.setOnClickListener { | ||
val intent = Intent(this, AddIPFSContent::class.java) | ||
intent.action = Intent.ACTION_SEND | ||
intent.type = "text/plain" | ||
intent.putExtra(android.content.Intent.EXTRA_TEXT, textEdit.text.toString()) | ||
startActivity(intent) | ||
} | ||
|
||
findViewById(R.id.gcButton)!!.setOnClickListener { | ||
Thread(Runnable { | ||
val gc = ipfs.repo.gc() | ||
|
||
runOnUiThread { | ||
AlertDialog.Builder(textEdit.context) | ||
.setMessage("Collected " + gc.size + " objects") | ||
.show() | ||
} | ||
}).start() | ||
} | ||
|
||
} | ||
|
||
} |
73 changes: 0 additions & 73 deletions
73
app/src/main/java/org/ligi/ipfsdroid/IPFSBinaryController.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.