-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add feature to export chats to text file.
- Loading branch information
Showing
9 changed files
with
108 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package xyz.rodit.snapmod.arroyo | ||
|
||
data class ArroyoMessage(val content: String, val timestamp: Long, val senderId: String) |
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
57 changes: 57 additions & 0 deletions
57
app/src/main/java/xyz/rodit/snapmod/features/chatmenu/ExportOption.kt
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,57 @@ | ||
package xyz.rodit.snapmod.features.chatmenu | ||
|
||
import android.content.Intent | ||
import androidx.core.content.FileProvider | ||
import xyz.rodit.snapmod.CustomResources.string.menu_option_export | ||
import xyz.rodit.snapmod.features.FeatureContext | ||
import xyz.rodit.snapmod.mappings.SelectFriendsByUserIds | ||
import java.io.File | ||
import java.text.SimpleDateFormat | ||
import java.util.* | ||
|
||
class ExportOption(context: FeatureContext): | ||
ButtonOption(context, "export_chat", menu_option_export) { | ||
|
||
override fun shouldCreate() = true | ||
|
||
override fun handleEvent(data: String?) { | ||
if (data == null) return | ||
|
||
val (messages, senders) = context.arroyo.getAllMessages(data) | ||
val friendData = | ||
context.instances.friendsRepository.selectFriendsByUserIds(senders.toList()) | ||
val senderMap = friendData.map(SelectFriendsByUserIds::wrap).associateBy { u -> u.userId } | ||
|
||
val dateFormat = SimpleDateFormat("dd/MM/yyyy, HH:mm:ss", Locale.getDefault()) | ||
|
||
val temp = File.createTempFile( | ||
"Snapchat Export ", | ||
".txt", | ||
File(context.appContext.filesDir, "file_manager/media") | ||
) | ||
temp.deleteOnExit() | ||
temp.bufferedWriter().use { | ||
messages.forEach { m -> | ||
val username = senderMap[m.senderId]?.displayName ?: "Unknown" | ||
val dateTime = dateFormat.format(m.timestamp) | ||
it.append(dateTime) | ||
.append(" - ") | ||
.append(username) | ||
.append(": ") | ||
.appendLine(m.content) | ||
} | ||
} | ||
|
||
val intent = Intent(Intent.ACTION_SEND) | ||
.setType("text/plain") | ||
.putExtra( | ||
Intent.EXTRA_STREAM, | ||
FileProvider.getUriForFile( | ||
context.appContext, | ||
"com.snapchat.android.media.fileprovider", | ||
temp | ||
) | ||
) | ||
context.activity?.startActivity(Intent.createChooser(intent, "Export Chat")) | ||
} | ||
} |
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