Skip to content

Commit

Permalink
Remove binaries now option to load them from ipfs.io
Browse files Browse the repository at this point in the history
Migrate more code to kotlin
Use the IPFS Kotlin API
  • Loading branch information
ligi committed Jun 14, 2016
1 parent 905f704 commit 26670cd
Show file tree
Hide file tree
Showing 25 changed files with 616 additions and 329 deletions.
23 changes: 19 additions & 4 deletions app/build.gradle
Expand Up @@ -10,8 +10,8 @@ android {

defaultConfig {
applicationId "org.ligi.ipfsdroid"
minSdkVersion 10
targetSdkVersion 23
minSdkVersion 15
targetSdkVersion 22
versionCode 4
versionName "0.4"
archivesBaseName = "IPFSDroid-$versionName"
Expand All @@ -23,11 +23,19 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

dexOptions {
incremental true
}

lintOptions {
// for OKIO
warning 'InvalidPackage'
}
}

dependencies {
apt "com.google.dagger:dagger-compiler:$dagger_version"
apt "com.jakewharton:butterknife-compiler:$butterknife_version"

testCompile "junit:junit:4.12"
testCompile "com.squareup.assertj:assertj-android:1.1.1"
Expand All @@ -41,7 +49,14 @@ dependencies {

compile "com.android.support:appcompat-v7:$support_version"
compile "com.android.support:design:$support_version"
compile "com.jakewharton:butterknife:$butterknife_version"
compile 'com.squareup.okhttp3:okhttp:3.3.0'
compile 'com.squareup.moshi:moshi:1.2.0'

compile 'net.steamcrafted:load-toast:1.0.10'

compile 'com.github.ligi:ipfs-api-kotlin:0.7'

compile 'org.ligi:AXT:0.36'

androidTestApt "com.google.dagger:dagger-compiler:$dagger_version"
}
13 changes: 13 additions & 0 deletions app/src/main/AndroidManifest.xml
Expand Up @@ -3,6 +3,8 @@
package="org.ligi.ipfsdroid">

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
Expand All @@ -21,6 +23,17 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

<activity android:name=".DetailsActivity"/>

<activity android:name=".AddIPFSContent">
<intent-filter>
<action android:name="android.intent.action.SEND"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="*/*"/>
</intent-filter>
</activity>

<activity android:name=".IPFSBrowseActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
Expand Down
Binary file removed app/src/main/assets/ipfs-android-16-386
Binary file not shown.
Binary file removed app/src/main/assets/ipfs-android-16-arm
Binary file not shown.
101 changes: 101 additions & 0 deletions app/src/main/java/org/ligi/ipfsdroid/AddIPFSContent.kt
@@ -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()

}

}
6 changes: 4 additions & 2 deletions app/src/main/java/org/ligi/ipfsdroid/AppComponent.java
Expand Up @@ -6,7 +6,9 @@
@Singleton
@Component(modules = {AppModule.class})
public interface AppComponent {
void inject(IPFSBrowseActivity ipfsBrowseActivity);

void inject(MainActivity mainActivity);

void inject(AddIPFSContent addIPFSContent);

void inject(DetailsActivity detailsActivity);
}
12 changes: 10 additions & 2 deletions app/src/main/java/org/ligi/ipfsdroid/AppModule.java
Expand Up @@ -2,7 +2,9 @@

import dagger.Module;
import dagger.Provides;
import io.ipfs.kotlin.IPFS;
import javax.inject.Singleton;
import okhttp3.OkHttpClient;

@Module
public class AppModule {
Expand All @@ -15,7 +17,13 @@ public AppModule(App app) {

@Singleton
@Provides
IPFSBinaryController provideBinaryController() {
return new IPFSBinaryController(app);
OkHttpClient proviceOkhttp() {
return new OkHttpClient.Builder().build();
}

@Singleton
@Provides
IPFS provideIPFS() {
return new IPFS();
}
}
61 changes: 61 additions & 0 deletions app/src/main/java/org/ligi/ipfsdroid/DetailsActivity.kt
@@ -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 app/src/main/java/org/ligi/ipfsdroid/IPFSBinaryController.kt

This file was deleted.

0 comments on commit 26670cd

Please sign in to comment.