Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
9001 committed Jan 11, 2022
1 parent 90eac4d commit 4a02a23
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 54 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Party UP!

upload files and links to a copyparty server by sharing them to this app
<a href="https://f-droid.org/packages/me.ocv.partyup/"><img src="https://ocv.me/fdroid.png" alt="Get it on F-Droid" height="50" /> '' <img src="https://img.shields.io/f-droid/v/me.ocv.partyup.svg" alt="f-droid version info" /></a> '' <a href="https://github.com/9001/party-up"><img src="https://img.shields.io/github/release/9001/party-up.svg?logo=github" alt="github version info" /></a>

upload files and links to a [copyparty](https://github.com/9001/copyparty) server by sharing them to this app

primarily made for this year's meadup, letting a room full of nerds throw memes onto the big screen

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
applicationId "me.ocv.partyup"
minSdk 28
targetSdk 28
versionCode 10201
versionName "1.2.1"
versionCode 10300
versionName "1.3.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.release
Expand Down
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 10201,
"versionName": "1.2.1",
"versionCode": 10300,
"versionName": "1.3.0",
"outputFile": "app-release.apk"
}
],
Expand Down
139 changes: 114 additions & 25 deletions app/src/main/java/me/ocv/partyup/XferActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package me.ocv.partyup;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.database.Cursor;
Expand All @@ -11,10 +14,13 @@
import androidx.appcompat.app.AppCompatActivity;

import android.provider.OpenableColumns;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.preference.PreferenceManager;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.InputStream;
Expand All @@ -25,20 +31,23 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.stream.Collectors;

import me.ocv.partyup.databinding.ActivityXferBinding;
import me.ocv.partyup.databinding.ContentXferBinding;

public class XferActivity extends AppCompatActivity {

private ActivityXferBinding binding;
private Intent the_intent;
private String the_msg;
private String base_url, full_url;
private Uri file_uri;
private String file_name;
private long file_size;
private String the_desc;
private boolean upping;
ActivityXferBinding binding;
SharedPreferences prefs;
Intent the_intent;
String the_msg;
String base_url, full_url, share_url;
Uri file_uri;
String file_name;
long file_size;
String the_desc;
boolean upping;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -49,6 +58,8 @@ protected void onCreate(Bundle savedInstanceState) {

setSupportActionBar(binding.toolbar);

prefs = PreferenceManager.getDefaultSharedPreferences(this);

Intent intent = getIntent();
String action = intent.getAction();
String type = intent.getType();
Expand All @@ -70,7 +81,7 @@ protected void onCreate(Bundle savedInstanceState) {
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
fab.setVisibility(View.INVISIBLE);
fab.setVisibility(View.GONE);
do_up();
}
});
Expand Down Expand Up @@ -143,7 +154,6 @@ private void do_up() {
upping = true;

try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
base_url = full_url = prefs.getString("server_url", "");
show_msg("Sending to " + base_url + " ...\n\n" + the_desc);

Expand Down Expand Up @@ -196,16 +206,30 @@ private void do_textmsg(HttpURLConnection conn) throws Exception {
OutputStream os = conn.getOutputStream();
os.write(body);
os.flush();
int rc = conn.getResponseCode();
share_url = "HTTP " + rc;
if (rc >= 300) {
byte[] buf = new byte[1024];
int n = Math.max(0, conn.getErrorStream().read(buf));
tshow_msg("Server error " + rc + ":\n" + new String(buf, 0, n, "UTF-8"));
conn.disconnect();
return;
}
conn.disconnect();
finishAndRemoveTask();
findViewById(R.id.upper_info).post(new Runnable() {
@Override
public void run() {
onsuccess(false);
}
});
}

private void do_fileput(HttpURLConnection conn) throws Exception {
conn.setRequestMethod("PUT");
conn.setFixedLengthStreamingMode(file_size);
conn.setRequestProperty("Content-Type", "application/octet-stream");
conn.connect();
final TextView tv = (TextView)findViewById(R.id.upper_info);
final TextView tv = (TextView) findViewById(R.id.upper_info);
OutputStream os = conn.getOutputStream();
InputStream ins = getContentResolver().openInputStream(file_uri);
MessageDigest md = MessageDigest.getInstance("SHA-512");
Expand All @@ -232,14 +256,14 @@ public void run() {
file_size - meme,
perc
));
((ProgressBar)findViewById(R.id.progbar)).setProgress((int)Math.round(perc));
((ProgressBar) findViewById(R.id.progbar)).setProgress((int) Math.round(perc));
}
});
}
os.flush();
int rc = conn.getResponseCode();
if (rc >= 300) {
int n = conn.getErrorStream().read(buf);
int n = Math.max(0, conn.getErrorStream().read(buf));
tshow_msg("Server error " + rc + ":\n" + new String(buf, 0, n, "UTF-8"));
conn.disconnect();
return;
Expand All @@ -249,20 +273,85 @@ public void run() {
for (int a = 0; a < 28; a++)
sha += String.format("%02x", bsha[a]);

String line, line2 = "<null>";
boolean ok = false;
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = br.readLine()) != null)
if (line.indexOf(sha) >= 0)
ok = true;
else
line2 = line;

String[] lines = br.lines().collect(Collectors.toList()).toArray(new String[0]);
conn.disconnect();
if (ok) {

if (lines.length < 3) {
tshow_msg("SERVER ERROR:\n" + lines[0]);
return;
}
if (lines[2].indexOf(sha) != 0) {
tshow_msg("ERROR:\nFile got corrupted during the upload;\n\n" + lines[2] + " expected\n" + sha + " from server");
return;
}
if (lines.length > 3 && !lines[3].isEmpty())
share_url = lines[3];
else
share_url = full_url.split("\\?")[0];

tv.post(new Runnable() {
@Override
public void run() {
onsuccess(true);
}
});
}

void onsuccess(Boolean upload) {
show_msg("✅ 👍\n\nCompleted successfully\n\n" + share_url);
((TextView)findViewById(R.id.upper_info)).setGravity(Gravity.CENTER);

if (prefs.getBoolean("autoclose", false)) {
finishAndRemoveTask();
return;
}
tshow_msg("ERROR:\nFile got corrupted during the upload;\n\n" + line2 + " expected\n" + sha + " from server");

findViewById(R.id.progbar).setVisibility(View.GONE);
findViewById(R.id.successbuttons).setVisibility(View.VISIBLE);

Button btn = (Button)findViewById(R.id.btnExit);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finishAndRemoveTask();
}
});

if (!upload) {
findViewById(R.id.btnCopyLink).setVisibility(View.GONE);
findViewById(R.id.btnShareLink).setVisibility(View.GONE);
return;
}

btn = (Button)findViewById(R.id.btnCopyLink);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ClipboardManager cb = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
ClipData cd = ClipData.newPlainText("copyparty upload", share_url);
Toast.makeText(getApplicationContext(), "Link copied", Toast.LENGTH_SHORT).show();
}
});

btn = (Button)findViewById(R.id.btnShareLink);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent send = new Intent(Intent.ACTION_SEND);
send.setType("text/plain");
send.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
send.putExtra(Intent.EXTRA_SUBJECT, "Uploaded file");
send.putExtra(Intent.EXTRA_TEXT, share_url);
//startActivity(Intent.createChooser(send, "Share file link"));

Intent view = new Intent(Intent.ACTION_VIEW);
view.setData(Uri.parse(share_url));

Intent i = Intent.createChooser(send, "Share file link");
i.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { view });
startActivity(i);
}
});
}
}
37 changes: 36 additions & 1 deletion app/src/main/res/layout/activity_xfer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,46 @@
android:layout_height="wrap_content"
android:layout_weight="1" />

<LinearLayout
android:id="@+id/successbuttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:orientation="horizontal"
android:visibility="gone">

<Button
android:id="@+id/btnCopyLink"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="copy\nlink" />

<Button
android:id="@+id/btnShareLink"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="share\nlink" />

<Button
android:id="@+id/btnExit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:text="close\napp" />
</LinearLayout>

<ProgressBar
android:id="@+id/progbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:scaleY="5" />

</LinearLayout>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<!-- https://materialui.co/colors -->
<color name="purple_200">#FFFFCC80</color> <!-- actually orange -->
<color name="purple_500">#FFFF9800</color>
<color name="purple_700">#FFF57C00</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
Expand Down
18 changes: 13 additions & 5 deletions app/src/main/res/xml/root_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,21 @@
app:useSimpleSummaryProvider="true" />

</PreferenceCategory>
<PreferenceCategory android:title="Behavior">

<CheckBoxPreference
android:defaultValue="false"
android:key="autoclose"
android:title="Autoclose"
app:summary="Quit on successful upload" />
</PreferenceCategory>
<PreferenceCategory android:title="About">

<CheckBoxPreference
android:defaultValue="false"
android:key="lbl_bver"
android:summary="1.3.0"
android:title="Version" />
</PreferenceCategory>
<CheckBoxPreference
android:defaultValue="false"
android:key="lbl_bver"
android:summary="1.2.1"
android:title="Version" />

</PreferenceScreen>
1 change: 1 addition & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
distributionSha256Sum=0e46229820205440b48a5501122002842b82886e76af35f0f3a069243dca4b3c
1 change: 1 addition & 0 deletions metadata/en-US/changelogs/10300.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
• new: copy/share link after upload
14 changes: 7 additions & 7 deletions metadata/en-US/full_description.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Send files and links to a <a href="https://github.com/9001/copyparty">copyparty</a> server by sharing them to this app

<b>Features:</b><ul>
<li>sha512-verified uploads</li>
<li>stash links and plaintext</li>
<li>supports HTTP and HTTPS</li></ul>
<b>Features:</b>
• sha512-verified uploads
• stash links and plaintext
• display/copy link to the uploaded files
• supports HTTP and HTTPS

<b>Future ideas:</b><ul>
<li>upload slicing (resumable + usually faster)</li>
<li>display/copy link to the uploaded files</li></ul>
<b>Future ideas:</b>
• upload slicing (resumable + usually faster)

This can be used to turn a raspi into a very flexible chromecast clone; see <a href="https://github.com/9001/party-up">the readme</a> for details
16 changes: 8 additions & 8 deletions metadata/nb-NO/full_description.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Send filer og lenker til en <a href="https://github.com/9001/copyparty">copyparty</a>-server ved å dele dem til denne appen

<b>Funksjoner per nu:</b><ul>
<li>sha512 garanterer at ting kommer helskinnet frem</li>
<li>arkivering av linker og annen klartekst</li>
<li>tar både HTTP og HTTPS</li></ul>
<b>Funksjoner per nu:</b>
• sha512 garanterer at ting kommer helskinnet frem
• arkivering av linker og annen klartekst
• vise/kopiere link til det som er lastet opp
• tar både HTTP og HTTPS

<b>Én gang i fremtiden:</b><ul>
<li>oppdeling av filer (ofte raskere, samt mulighet for å gjenoppta avbrutte opplastninger)</li>
<li>vise/kopiere link til det som er lastet opp</li></ul>
<b>Én gang i fremtiden:</b>
• oppdeling av filer (ofte raskere, samt mulighet for å gjenoppta avbrutte opplastninger)

Kan forøvrig brukes for å gjøre en raspi om til en særdeles fleksibel chromecast-aktig sak; se <a href="https://github.com/9001/party-up">readme'n</a> for litt mer info
Kan forøvrig brukes for å gjøre en raspi om til en særdeles fleksibel chromecast-aktig sak; se <a href="https://github.com/9001/party-up">readme'n</a> for litt mer info

0 comments on commit 4a02a23

Please sign in to comment.