Implement Structured Data on Commons (SDC) support and UX improvements#104
Merged
Conversation
implements the functionality to automatically add Structured Data on Commons (SDC) to audio files after they are successfully uploaded. This enhances the metadata of uploaded recordings with machine-readable information such as inception date, media type, copyright status, and creator details.
**Key Changes:**
**1. SDC Infrastructure:**
- **`SdcUtils.kt`**: Created a new utility class to construct the complex SDC JSON payload. It handles:
- Mapping app license preferences to Wikibase Q-IDs (e.g., CC0, CC BY-SA 4.0).
- Creating statements for Inception (P571), Media type (P1163), Copyright status (P6216), Copyright license (P275), Source of file (P7482), and Creator (P170) with qualifiers for username and URL.
- **`WikiSdcData.kt`**: Added data classes to model SDC API responses and entity structures.
**2. API Integration (`ApiInterface.kt`):**
- Added `getPageInfo()` to retrieve the `pageid` for a specific file title.
- Added `updateStructuredData()` to perform the `wbeditentity` API action for updating SDC claims.
**3. Upload Workflow (`RecordAudioActivity.kt`):**
- **Trigger**: Upon a successful file upload, `updateSdcForUploadedFile()` is now invoked.
- **Entity Resolution**: Implemented `getFileEntityId()` to convert file names into the "M-ID" format (e.g., `M12345`) required by the Wikibase API.
- **Async Execution**: The SDC update runs asynchronously to ensure the user is notified of the upload success without waiting for metadata processing.
- **Logging**: Added comprehensive logging for the SDC update lifecycle, including page ID resolution and API response handling.
**4. Constants:**
- Added `SDC_UPDATE_COMMENT` to `AppConstants.kt` for use as the edit summary during metadata updates.
This change ensures that all audio contributions via Spell4Wiki are better indexed and compliant with modern Wikimedia Commons metadata standards.
This commit refactors the `SdcUtils` class to improve the structure of generated JSON for Wikimedia Structured Data on Commons. It also updates internal application constants for consistency in edit summaries. **Key Changes:** **1. `SdcUtils.kt`:** - **Reordered Statements:** Updated `buildSdcDataForAudioFile` to follow a more standard property order: Creator (P170), Copyright Status (P6216), License (P275), Inception (P571), Media Type (P1163), and Source (P7482). - **Documentation:** Added reference links to Wikidata and Wikimedia Commons documentation for various properties (P170, P6216, P275, P571, P7482) to improve maintainability and adherence to modeling standards. - **Code Cleanup:** Removed unused imports (`Gson`, `com.manimarank.spell4wiki.data.model.*`) and reordered private helper methods (`createWikibaseItemStatement`, `createStringStatement`, `createTimeStatement`) to improve file readability. **2. `AppConstants.kt`:** - **Update Comment:** Revised `SDC_UPDATE_COMMENT` to include a link to the app's Commons page (`"Adding structured data using [[:Commons:Spell4Wiki|Spell4Wiki]] app."`), aligning it with the standard `UPLOAD_COMMENT` format.
This commit updates the Structured Data on Commons (SDC) generation logic to use more accurate media types and date handling. It also enhances user feedback by surfacing SDC update failures in the UI. **Key Changes:** **1. `SdcUtils.kt`:** - **Media Type Correction**: Updated the P1163 (Media type) value from `application/ogg` to the more appropriate `audio/ogg`. - **Date Handling**: Refactored `createTimeStatement` to generate the current UTC date internally using `SimpleDateFormat` instead of accepting it as a parameter. This simplifies the `buildSdcDataForAudioFile` signature and ensures consistency. - **Copyright Status**: Added support for "PD" (Public Domain) mapping to Q-ID `Q19652`. - **Code Cleanup**: Removed unused `DateUtils` imports. **2. `RecordAudioActivity.kt`:** - **Enhanced Error Reporting**: Added `runOnUiThread` calls to display Toast messages (`showLong`) when SDC updates fail or encounter API errors. - **Error Parsing**: Implemented JSON parsing of the API response body to extract and display specific error information from the Wikibase API. - **Method Signature Update**: Adjusted the call to `SdcUtils.buildSdcDataForAudioFile` to match the new simplified signature.
…ates
This commit introduces a new setting that allows users to enable or disable automatic Structured Data on Commons (SDC) updates for their file uploads.
**Key Changes:**
**1. UI and Resources:**
- **`strings.xml`**: Added string resources for the SDC update setting title and a descriptive text including a link to the Wikimedia Commons documentation.
- **`activity_settings.xml`**: Added a new `LinearLayout` containing a switch and description text to the settings screen to allow users to toggle SDC updates.
**2. Settings Logic:**
- **`SettingsActivity.kt`**:
- Implemented logic to initialize the SDC toggle state from preferences.
- Added a listener to save the user's preference when the toggle is changed.
- Handled the visibility of the SDC setting section based on the user's login state.
- Enabled HTML link movement for the description text.
**3. Data Management:**
- **`PrefManager.kt`**: Added `isSdcUpdateEnabled` to the shared preferences manager to persist the user's choice, defaulting to `true`.
**4. Upload Workflow:**
- **`RecordAudioActivity.kt`**: Modified the upload success handler to check the `isSdcUpdateEnabled` preference before triggering the `updateSdcForUploadedFile` function.
Introduces a utility class to standardize the extraction and display of error messages from API responses, network failures, and exceptions. This replaces repetitive, hardcoded error strings with more informative messages, including specific Wikimedia API error details when available.
**Key Changes:**
**1. Error Handling Infrastructure:**
- **`ApiErrorUtils.kt`**: Created a new utility object to process Retrofit `Response` objects and `Throwable` instances.
- It parses JSON error bodies to extract specific Wikimedia "info" or "code" fields.
- It maps common network exceptions (e.g., `UnknownHostException`, `SocketTimeoutException`) to user-friendly messages like "Check your internet connection."
- It provides a fallback that includes HTTP status codes for easier debugging.
**2. Activity Integrations:**
- **`LoginActivity.kt`**: Updated all login and token retrieval steps to use `ApiErrorUtils`, providing better feedback during authentication failures.
- **`RecordAudioActivity.kt`**:
- Refactored file upload and CSRF token retrieval to use the new utility.
- Streamlined Structured Data on Commons (SDC) update error logging by replacing manual JSON parsing with `ApiErrorUtils.extractWikiErrorFromJson`.
- **`WiktionarySearchActivity.kt`** & **`Spell4Wiktionary.kt`**: Improved search failure reporting by surfacing specific API error info instead of generic "Something went wrong" messages.
- **`ContributorsActivity.kt`**: Updated contributor list fetching to handle network and API errors consistently.
**3. Cleanup:**
- Removed redundant string formatting logic and unused imports in `RecordAudioActivity.kt`.
- Improved error visibility by including exception messages and API error codes in UI toasts and logs.
This commit introduces a checkbox in the audio recording popup that allows users to toggle Structured Data on Commons (SDC) updates directly before uploading. It also includes UI refinements for better alignment of the declaration and settings components.
**Key Changes:**
**1. UI Enhancements (`activity_record_audio_pop_up.xml`):**
- **Added SDC Toggle**: Included a new `AppCompatCheckBox` (`checkboxSdcUpdate`) to allow users to enable or disable SDC updates for the current session.
- **Layout Adjustments**:
- Reorganized the declaration section for better spacing, adding `layout_marginTop` to the container.
- Adjusted gravity and margins for `checkboxDeclaration` and `btnSettings` to improve visual alignment.
**2. Logic Integration (`RecordAudioActivity.kt`):**
- **State Management**: Linked the new SDC checkbox to the application preferences (`pref.isSdcUpdateEnabled`).
- **Listener Implementation**: Added an `OnCheckedChangeListener` to persist the user's SDC preference immediately when toggled.
**3. Resources (`strings.xml`):**
- Added `sdc_update_setting_short` for the checkbox label in the recording UI.
This commit adjusts margins and button dimensions in the `activity_record_audio_pop_up.xml` layout to create a more compact UI.
**Key Changes:**
- **`activity_record_audio_pop_up.xml`**:
- **Margins**: Reduced `layout_marginBottom` for the language label (8dp to 4dp), upload button (6dp to 2dp), and close button (8dp to 2dp).
- **Margins**: Reduced `layout_marginTop` for the upload button from 8dp to 4dp.
- **Dimensions**: Decreased the height of the Close button (`btnClose`) from 48dp to 42dp.
…yclerView` This commit optimizes how pagination and item notifications are handled in the custom endless scrolling implementation to prevent potential crashes and inconsistent UI states. **Key Changes:** **1. `EndlessRecyclerView.kt`:** - **UI Thread Safety**: Wrapped the "load more" logic inside `recyclerView.post`. This ensures that data loading triggers and adapter notifications are executed on the main thread and avoid "Cannot scroll/compute scroll offset while RecyclerView is computing a layout or scrolling" errors. - **Double-Check Validation**: Re-verifies `isLoading` and `loadMoreEnabled` states within the posted Runnable to prevent redundant loading calls if the state changed between the scroll event and the execution of the block. **2. `EndlessRecyclerAdapter.kt`:** - **Refactor Notification**: Removed the redundant `Handler().post` wrapper around `notifyItemInserted`. Since the calling logic is now properly synchronized or expected to be on the UI thread, this direct call reduces unnecessary overhead.
This commit improves the user experience in web-based activities by allowing users to navigate backward through their browsing history using the system back button or the toolbar home button, rather than immediately closing the activity. **Key Changes:** **1. `CommonWebActivity.kt`:** - **Back Navigation**: Overrode `onBackPressed` to check if the hosted fragment can navigate backward. If so, it triggers `fragment.backwardWebPage()`; otherwise, it performs the default back action. - **Toolbar Integration**: Updated the `android.R.id.home` menu item logic to call `onBackPressed()` instead of `finish()`, ensuring consistent navigation behavior. **2. `CommonWebContentActivity.kt`:** - **WebView History**: Overrode `onBackPressed` to navigate back in the `WebView` history using `binding.webView.goBack()` if a previous page exists. - **Toolbar Integration**: Updated the home button listener to trigger the new `onBackPressed` logic.
This commit updates the application versioning in the build configuration.
**Key Changes:**
- **`app/build.gradle.kts`**:
- Updated `versionName` from "3.3" to "4.0".
- Incremented `versionCode` from 21 to 22.
This commit updates the project documentation and Play Store metadata to reflect a new milestone of 50,000+ uploads and adds the changelog and screenshots for the latest release.
**Key Changes:**
- **Project Statistics**: Updated `README.md` and the Android store's full description to reflect that 50,000+ audio files (up from 40,000+) have been uploaded to Wikimedia Commons.
- **Changelog**: Added `22.txt` to the Fastlane metadata, outlining the following improvements:
- Support for Structured Data on Commons (SDC).
- User toggles for SDC updates in settings and recording popups.
- Web page back-navigation support.
- Enhanced API error handling and UI layout refinements.
- **Visual Assets**: Updated store screenshots (`2.png`, `4.png`, and `5.png`) to reflect recent UI changes and features.
Owner
Author
|
Fixed #34 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎉 Spell4Wiki v4.0
✨ What's New
Thank you for contributing audio pronunciations to Wiktionary and Wikimedia Commons! 🌍